idmillington / cyclone-physics

The Physics engine that accompanies the book "Game Physics Engine Design"
MIT License
946 stars 265 forks source link

Simple Getting Started with rotations #38

Open MarkF2 opened 9 years ago

MarkF2 commented 9 years ago

Sorry...I have been staring at this too long, and thought I would ask for help.

quaternion.rotateByVector is not having the effect that I am expecting.

Can someone post simple examples: setOrientation(); --> Is default orientation along the x-axis? (I assume yes: If I use getAxisVector(0), I get (1,0,0))

  1. How do I set a 10-degree rotation around the z-axis with setOrientation()?
  2. If I start from the default orientation, how do I then rotate 10 degrees by using rotateByVector()
ejosiah commented 7 years ago

q = [ cos(t/2), sin(t/2), sin(t/2), sin(t/2)] 1.) rotate 10 degrees about z axis = [cos(10/2), 0, 0, sin(10/2) ] (if trig functions are in radians then multiply by π/180 before applying them)

2.) 10 π/180 axis of rotation (this is your angular velocity) apply this in the addScaled method with scale 1 (rotateBy is for combining rotations)