Jump to content
• Advertisement  # yezu666

Member

5

100 Neutral

## About yezu666

• Rank
Newbie
1. Thanks for the suggestion. I've tried this method but I don't seem to get a correct transformation from it. I'll keep trying, though
2. Well Indeed I made a typo. The part: forward.setY(-forward.getY());is not needed. (Fixed it BTW ) I remove the Y component, because the upper method didn't provide proper rotation for it. So effectively I've split the operation into two rotations and then I multiply the resulting matrices. The method is not very straight forward but provides correct results. I'd gladly change it I if could find something simpler that calculates correctly. Although I haven't noticed so far, I think there are errors in my LookAt function. AFAIK the resulting matrix should be orthonormal and the scaling effect after transposition suggests it is not. I must look into it. However I would be very happy if You could help me. Here is the code: public static TransformationMatrix calculateLookAtMatrix(Vector3d eye, Vector3d center, Vector3d up) { float [] matrix = new float; Vector3d forward = Vector3d.sub(center , eye); forward.normalize(); Vector3d side = Vector3d.cross(forward , up); side.normalize(); Vector3d plane_up = Vector3d.cross(side , forward); plane_up.normalize(); matrix = side.getX(); matrix = plane_up.getX(); matrix = -forward.getX(); matrix = 0.0f; matrix = side.getY(); matrix = plane_up.getY(); matrix = -forward.getY(); matrix = 0.0f; matrix = side.getZ(); matrix = plane_up.getZ(); matrix = -forward.getZ(); matrix = 0.0f; matrix = 0.0f; matrix = 0.0f; matrix = 0.0f; matrix = 1.0f; Vector3d neweye = new Vector3d(eye); neweye.reverse(); TransformationMatrix ret = new TransformationMatrix(matrix); ret.multiply(TransformationMatrix.calculateTranslationMatrix(neweye)); return ret; } thanks a lot for the help
3. Ok. Solved. Sort of I've managed to implement a function using hybrid method. It seems to work. However is not very elegant. For anyone interested: public static TransformationMatrix calculateDirectionalMatrix(Vector3d dir, Vector3d up) { float [] matrix = new float; //Calculating as if a normal LookAt function: Vector3d forward = new Vector3d(dir); //Only with inverted direction and no height component. forward.setX(-forward.getX()); forward.setY(0.0f); forward.normalize(); Vector3d side = Vector3d.cross(forward , up); side.normalize(); Vector3d plane_up = Vector3d.cross(side , forward); plane_up.normalize(); matrix = side.getX(); matrix = plane_up.getX(); matrix = -forward.getX(); matrix = 0.0f; matrix = side.getY(); matrix = plane_up.getY(); matrix = -forward.getY(); matrix = 0.0f; matrix = side.getZ(); matrix = plane_up.getZ(); matrix = -forward.getZ(); matrix = 0.0f; matrix = 0.0f; matrix = 0.0f; matrix = 0.0f; matrix = 1.0f; //Complete directional matrix for the XZ part of the direction. TransformationMatrix ret = new TransformationMatrix(matrix); //Now if relevant we calculate the height component of the direction using the trigonometry function. if(dir.getY() != 0.0f) { float angle = (float)Math.toDegrees(Math.asin(dir.getY())); TransformationMatrix Y = TransformationMatrix.calculateRotationMatrix(angle, 0.0f, 0.0f); //We multiply matrices as D = XZ * Y; ret.multiply(Y); } //TADA! return ret; }
4. Thanks for the answer I'm trying to experiment with the transpose of the rotational part of the LookAt matrix, without much success unfortunately. However the weird thing is that with the transposed matrix I get some scaling effects when applied to a mesh. Should that happen?
5. Hello! I've been trying to solve a (rather simple?) problem lately. I'm surprised I haven't been able to find anything really useful on the net so far. The thing is I have 3d direction vector. Use it to set the direction of an object in 3d space. To do that I need of course a transformation matrix. I have a function that properly calculates the LookAt matrix. However it is correct for the view transformation. I had no success in using it to calculate the rotation of the object. I have also tried using trigonometry using (assuming Y is up): if(dir.getY() != 0.0f) xAngle = (float)Math.toDegrees(Math.atan((dir.getZ()*dir.getZ()+dir.getX()*dir.getX())/dir.getY())); if(dir.getZ() != 0.0f) yAngle = (float)Math.toDegrees(Math.atan(dir.getX()/dir.getZ())); TransformationMatrix.calculateRotationMatrix(xAngle, yAngle, 0.0f); However this does produce proper results only in certain situations. Can anybody suggest a solution? Thanks a lot
• Advertisement
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!