Jump to content
  • Advertisement
Sign in to follow this  

Transformation Problem

This topic is 5030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, guys. I'm using C# and Managed DX. Right now I'm making a pool game. However, I'm having trouble drawing the cue stick. A stick is a cylinder that runs along the Z-axis. The coordinates of the stick are in cue-ball coordinates. Cue.Position is where the butt of the cue is. Cue.Stick is a vector along the axis of the stick, from the butt to the tip. Of course, I'll have to rotate the Z-axis-aligned cylinder along a vector that is perpendicular to the cue.Stick vector that is projected on the ground. Hence
Vector3 axis = Vector3.Cross(cue.Stick,new Vector3(cue.Stick.X,cue.Stick.Y,0));
Next, how much do we rotate it by?
    / |
   /  |
  /   |
 /    |
The diagonal is the cue. The height is cue.Position.Z. The length is cue.Stick.Length(). If theta is the bottom-left corner, theta = arcsin(cue.Position.Z/cue.Stick.Length()) because sin(theta) = opp/hyp. Then the angle of the top corner (which is the one I'm trying to rotate by is pi/2 - theta.
float angle = (float)Math.PI/2 - (float)Math.Asin(cue.Position.Z/cue.Stick.Length());
Now all that's left is to transform the cue Mesh, which is initially Z-aligned.
device.Transform.World = Matrix.Identity * Matrix.Translation(ballPosition) * 
				Matrix.Transformation(new Vector3(),new Quaternion(),
                                                      new Vector3(),new Vector3,
However, I can't even see the cue when I do this. I can't tell what I'm doing wrong. I mean I expect a couple mistakes in my math, but I can't see any part of the cue. I tried to simply draw a vertical cue and that works so I know my rendering code is OK. It's the transformation that's screwing it up. I can't tell for the life of me what's wrong with it. Please help. Thanks in advance.

Share this post

Link to post
Share on other sites
Haven't used Managed DirectX so not sure about the code part, but try converting your angles to radians. If I'm not wrong, DirectX uses radians for the rotation functions.

I didn't understand why you are multiplying with the ballPostition translation. Are you translating the entire cue to the position of the ball? You are already translating the cue to the cue.Position in the Matrix.Transformation function. Maybe I've it wrong....

Share this post

Link to post
Share on other sites
My angles are in radians, as far as I can tell. Also, I'm multiplying by the ball position because the cue is in cue-ball coordinates. I'm then multiplying by the actual cue coordinates.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!