Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Ortho Near/Far not working as I expected


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Krum110487   Members   -  Reputation: 110

Like
0Likes
Like

Posted 17 August 2012 - 04:26 PM

ok I am having an issue where I have a plane which I am spinning in 3d space, and it is getting cut off then the edge is to far away, or past the near.

so I figured I would set the near and far to really high numbers to see if that would fix it, but it doesn't seem to matter, does ortho not cover this?

GL.Ortho(0, screen_width, screen_height, 0, -10000, 10000);
GL.Viewport(0, 0, screen_width, screen_height);

then the render code is this:
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();


//GL.Scale(.5,.5,.5);
GL.Rotate(video_rotation_x % 360, 0, 1, 0);
GL.Rotate(video_rotation_y % 360, 1, 0, 0);
GL.Rotate(video_rotation_z % 360, 0, 0, 1);

GL.Begin(BeginMode.Quads);
GL.TexCoord2(0, 0);
GL.Vertex2(x, y);
GL.TexCoord2(1, 0);
GL.Vertex2(x + (float)video_width, y);
GL.TexCoord2(1, 1);
GL.Vertex2(x + (float)video_width, y + (float)video_height);
GL.TexCoord2(0, 1);
GL.Vertex2(x, y + (float)video_height);
GL.End();

I assumed that the -10000 would be more than enough for the near, but the corners at certain angles is cut off (looks flat) and I am just curious as to why, the video is not wider than 800 and it is at 0, so the max it could be is -800 right? maybe a bit further, but shouldn't come near -10,000, but no matter what value I use, it doesn't seem to make a difference.

also if I scale it to .5, .5, .5 it isn't clipped at all, so I am not sure how to fix it.

what am I missing?

Edited by Krum110487, 17 August 2012 - 04:31 PM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 30989

Like
2Likes
Like

Posted 17 August 2012 - 10:27 PM

GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();

This is replacing your ortho projection matrix with an 'identity' projection matrix.

You should probably be activating the Projection matrix-mode before setting your ortho matrix, and then setting the ModelView matrix-mode before setting identity + rotating.

Edited by Hodgman, 17 August 2012 - 10:28 PM.


#3 Krum110487   Members   -  Reputation: 110

Like
0Likes
Like

Posted 18 August 2012 - 01:08 AM

ok this is weird, if the matrix is "replaced" then why does commenting out ortho have a different result?

I set the ortho, for the width and height, then I set the Matrix mode, if that is truly replacing the matrix then there shouldn't be any difference between

GL.Ortho(0, screen_width, screen_height, 0, -10000, 10000);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();

or

//GL.Ortho(0, screen_width, screen_height, 0, -10000, 10000);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();

but there is most definitely a difference, BUT I think I just figured out what may be wrong (as I was typing)

I think matrix mode generates the projection Identity matrix using the current matrix, BUT it will remove the z index stuff because a projection matrix has a 0 for the z index.
screen_height 0            0
0             screen_width 0
0             0            0

or something of that sort, am I close?

Edited by Krum110487, 18 August 2012 - 01:16 AM.


#4 Hodgman   Moderators   -  Reputation: 30989

Like
1Likes
Like

Posted 18 August 2012 - 02:03 AM

MatrixMode selects which built-in matrix will be modified by the following matrix commands. Before you call Identity+Ortho, you should select the Projection matrix -- this matrix is used to transform camera-space positions to the screen.

Before you call Identity+Rotate, you should select the ModelView matrix -- this matrix is used to position the object (model) and camera (view).

In your original, you're not selecting a mode before calling Ortho, so maybe it's defaulting to the ModelView matrix. This means that you'd have them backwards: your ortho-projection in the ModelView, and your camera/object rotation in the Projection. This might have strange results, as the operations will be done in the wrong order.

N.B. LoadIdentity "clears" the currently selected matrix; you should use it before setting up any matrix from scratch.

Edited by Hodgman, 18 August 2012 - 02:04 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS