I'm making a 3d orthogonal-projected, game using painters' algorithm in java.

I'm able to rotate the objects with incremental rotations (e.g. rotate all objects 10 degrees) using affine transformations, but that involves changing/saving the rotated positions of the objects.

I want be able to rotate using a viewing direction vector. What is the maths and/or java code to do this?

Assume the default viewing direction (no rotation needed) would be (0,0,1) (looking down the z axis).

I can elaborate and/or clarify if wanted.

EDIT: What I'm doing currently:

for all drawable things:

// using transform matrices (translate to origin, rotate around origin, translate back)

rotate around center by x,y,z radians

What I want:

for all drawable things:

rotate around center using viewing direction (vector)

  • \$\begingroup\$ How do you rotate and draw your objects right now? Give us some code. \$\endgroup\$ – kolenda Sep 22 '14 at 12:05
  • \$\begingroup\$ It sounds like you might be referring to billboarding where all objects face the camera no matter where the camera moves to. Is that correct? \$\endgroup\$ – Steve H Sep 22 '14 at 14:29
  • \$\begingroup\$ @SteveH I have some objects which billboard (they're images that always face the viewer), others that don't. \$\endgroup\$ – Will Hardwick-Smith Sep 22 '14 at 22:32
  • \$\begingroup\$ If you're willing to do a bit of learning, read up on quaternions (en.wikipedia.org/wiki/Quaternions_and_spatial_rotation). It might be more helpful to google it in relation to game development \$\endgroup\$ – Aralox Sep 23 '14 at 3:44
  • \$\begingroup\$ OK thanks, I may use these if I can figure out how to use them. Is it possible to do this with affine transformation matrices? \$\endgroup\$ – Will Hardwick-Smith Sep 23 '14 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.