Hello,
I took the hellocollision code and have been trying to play with CharacterControl. Could anyone please tell me how to rotate the character here? I think what I am trying to do is try to do the same thing as the default mappings for up/down/right/left buttons.
I tried using getViewDirection and setView Direction but haven’t been able to get the desired results. This is how my code looks for now:
[java]
Vector3f vectorA=player.getViewDirection();
Quaternion roll= new Quaternion();
roll.fromAngleAxis(-FastMath.QUARTER_PI, Vector3f.UNIT_Y);
Vector3f vectorB=roll.mult(vectorA);
player.setViewDirection(vectorB);
…
…
[/java]
Could anyone please help me here?
I think fromAngleAxis returns a new quaternion.
So you should do:
[java]Quaternion roll= new Quaternion().fromAngleAxis(-FastMath.QUARTER_PI, Vector3f.UNIT_Y);[/java]
instead of
[java]Quaternion roll= new Quaternion();
roll.fromAngleAxis(-FastMath.QUARTER_PI, Vector3f.UNIT_Y);
[/java]
Check the code/javadoc:
[java]
/**
- <code>fromAngleAxis</code> sets this quaternion to the values specified
- by an angle and an axis of rotation. This method creates an object, so
- use fromAngleNormalAxis if your axis is already normalized.
*
-
@param angle
-
the angle to rotate (in radians).<br />
-
@param axis
-
the axis of rotation.<br />
-
@return this quaternion
*/
public Quaternion fromAngleAxis(float angle, Vector3f axis) {
Vector3f normAxis = axis.normalize();
fromAngleNormalAxis(angle, normAxis);
return this;
}
[/java]
It quite clearly doesn’t return a new Quaternion…