Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

gavcc

Problem with projection and rotation

This topic is 6692 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 all, If I take these four points: * * C * * and rotate them about the X-Axis they go off along the Z-Axis ... why is this ? If I set the view matrix to look along the Z-Axis and rotate them, then everything is fine. But when I add projection it does''nt. This is how I tranforming the points: Rotate Local --> World World --> View View --> Projection --> Screen Can someone help ? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I''ve been told that replying to an item moves it to the top of the list !!!

Could someone help me out here ?!?!?!

Share this post


Link to post
Share on other sites
gavcc,

I had a hell of a lot of problems with projection /cameras to begin with so I feel obligated to try and help here.

Perhaps you could be a bit more specific about what you are doing exactly. I might be able to able to assist you if you post/send me some snippets of code or just expand on what process you are following.

Does the problem lie with your local object rotations or camera rotations?

Oh,.. and that idea of replying to your own posts is very childish...I do that too!!

Paulcoz.

Edited by - paulcoz on 4/18/00 3:59:20 AM

Share this post


Link to post
Share on other sites
Thanks for the reply ...

... the problem is that I want to rotate the 4 points around the local axis and then have them projected to the screen.

I do the local rotations then tranform them to world -- view and then add perspective projection -- create screen co-ordinates.

But instead of rotating around the local axis the points zoom down the Z-axis into the screen until they reach the far plane and then start moving back out of the screen until the reach the near plane and it repeats this.

As i say if I don''t add perspective projection is works fine so the problem is there. After reading somewhere I did read something about including the distance between the camera position and the near plane in the projection matrix but I can''t see where to include this.

I''ve included the projection code and would welcome suggestions ...

CLFLOAT w = clf_Aspect * (cosf(clf_Fov / 2) / sinf(clf_Fov / 2));
CLFLOAT h = 1.0f * (cosf(clf_Fov / 2) / sinf(clf_Fov / 2));
CLFLOAT Q = clf_f / (clf_f - clf_n);

ZeroMemory(&proj, sizeof(D3DMATRIX));
clSetIdentityMatrix(proj);

proj._11 = w;
proj._22 = h;
proj._33 = Q;
proj._34 = 1.0f;
proj._43 = -Q * clf_n;

Thanks

Share this post


Link to post
Share on other sites
I'd say there's a very high chance your code is fine except that the field of view is incorrectly applied.

You definitely need to take into account the distance from the camera to the screen - until I added that to my program the objects in my world did the same thing eg. zoomed off into the distance along the z-axis.

Adjusting for the screen-distance is just a matter of: (a) dividing your z values by a set distance, or (b) multiplying your x and y values by a set distance. You do this during your perspective-projection, and (a) probably makes more sense.

If you tell me what the variables you mentioned do (w, h, q and the others) I can probably work out where this should go in the code - I'm not familiar with D3D and there is probably a pre-written function you can use to account for this.

I hope this helps,
Paulcoz.

Edited by - paulcoz on 4/23/00 8:59:28 PM

Share this post


Link to post
Share on other sites
yeah, i''ve had the same problems. i still haven''t found a way around them (i''ve used dozens of perspective trans matrix formulas i''ve found various places). the only way i can get anything 3d to draw correctly (in perspective, that is) is to modify the d3dframework source from some of the dx7 demos.
what really makes no sense to me, is i can setup the devices and matrices with exactly the same values and states in my own app, but my results are totally hosed unless i use that source from the dx7 demos.
i would really prefer to use my own framework, but seeing as i have no other option, maybe i''m stuck with ms''s.
nVidia has a d3d wrapper out that i dl''d, if it works out i''ll let ya know.

good luck,


crazy166
some people think i'm crazy, some people know it

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!