jPCT - a 3d engine for Java > Support

Rotation Towards 3D Point

(1/3) > >>

AGP:
The following isn't working. How come?


--- Code: ---     public void rotateTowards(SimpleVector towards) {
SimpleVector directionVector = new SimpleVector(towards.x -model.getTransformedCenter().x, towards.y -model.getTransformedCenter().y, towards.z -model.getTransformedCenter().z).normalize();//WON'T WORK WITH OR WITHOUT NORMALIZE()
Matrix rotationMatrix = directionVector.getRotationMatrix();
if (this instanceof Worker)
     ((Worker)this).setRotationMatrix(rotationMatrix);
else model.setRotationMatrix(rotationMatrix);
     }

--- End code ---

EgonOlsen:
"isn't working" doesn't really tell me much. You have to keep in mind that getRotationMatrix() gives you some rotation matrix that does the job, but it makes no assertion about the up-vector of the resulting matrix. If you need that, you would have to use the method that takes an additional up vector.

AGP:
Most of the time it rotates in the wrong direction, sometimes it doesn't rotate at all. My game is on the x/z plane, but which method takes an up vector?

AGP:
Oh, it should be noted that I already have both vectors in worldspace (my plane consists of multiple smaller planes that collide with the raycast mouse then just give me their transformed center).

EgonOlsen:
That one does: http://www.jpct.net/doc/com/threed/jpct/SimpleVector.html#getRotationMatrix(com.threed.jpct.SimpleVector)

Navigation

[0] Message Index

[#] Next page

Go to full version