jPCT - a 3d engine for Java > Support

Rotation Towards 3D Point

(1/3) > >>

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)
else model.setRotationMatrix(rotationMatrix);

--- End code ---

"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.

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?

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).

That one does:


[0] Message Index

[#] Next page

Go to full version