Jump to content
  • Advertisement
Sign in to follow this  

Orthonornal projection issues.

This topic is 3434 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 am developing a general purpose GUI library in C# DX9 and I was using transformed vertices . That worked out all right. Now I want to move onto positioned vertices so get some more flexibility, moving resizing etc without having to rebuild my buffers. So first step is to define the quads that are the minimal bounding box for the controls. To increase the intuitive feel I define them with upper left at (0,0) and then unit length and height. Next is to setup the matrices. By default the world matrix is identity, and the view and projection is defined as:
Matrix.LookAtLH(new Vector3(width/2,height/2,1),new Vector3(width/2,height /2,0),new Vector3(0,-1,0));
Matrix.OrthoOffCenterLH( -width/2, width/2, -height/2, height/2, 0.01f, 10.0f );
And when rendering is define the transform matrix for a control c as:
Matrix.Scaling( new Vector3( c.Width, c.Height, 1.0f ) ) *
Matrix.RotationYawPitchRoll( 0.0f, 0.0f, 0.0f ) *
Matrix.Translation( new Vector3( c.Position.X, c.Position.Y, 0.0f ) );
Note that the positions are relative to parent control if no parent then screen. This places the control right where i want it so that the control (x,y) correspond to the screen coordinates. So far so good. The problem arises when i want to draw control part inside another control. Each control has a texture which is the graphical representation of the control and child controls rendered onto it. Thereby saying it is also used as render target. Say W is a window and L is a label in W. To draw W i must first draw W's layout and then draw L onto W. Drawing W and only W is no problem but when drawing L onto W I do as follows: 1. I swap render targets setting W's texture as render surface. 2. Push new view and projection matrices to correspond texture dimension of W.
Matrix.LookAtLH(new Vector3(W.Width/2,W.Height/2,1),new Vector3(W.Width/2,W.Height /2,0),new Vector3(0,-1,0));
Matrix.OrthoOffCenterLH( -W.Width/2, W.Width/2, -W.Height/2, W.Height/2, 0.01f, 10.0f );
3. Render L using same transformation matrix as listed above. 4. Pop matrices and reset render target to previous. Somehow L is not placed where I want it, in fact it does not show. Not excluding my code is broken elsewhere, is this a correct approach? I was pretty certain until the results showed me something else. Sorry for the long post >.<

Share this post

Link to post
Share on other sites
In general I find that using RenderTargets isn't such a hot idea for clipping controls. It requires a whole lot of overhead and extra code for something you can acheive by other means. Personally I just use clipping rectangles. Each control figures out its clipping rectangle in screen space, and then figures out the rectangle that is the intersection of this bounding rectangle and the bounding rectangle of its parent. Then it draws itself and all children, and the clipping rectangle handles clipping. This also means you can just figure out the absolute position each Control based on its parent position, without having to adjust based on the parent's scale or anything like that.

Share this post

Link to post
Share on other sites
Thanks for the reply.
Well clipping is the least of my problems really. I am thinking general positioning.
So for instance when dragging a control I do not have to recalibrate all child components screen position.
I got this idea also, that it would be pointless to redraw, say, 30 tiny controls each frame when they are static (unless clicked, typed in whatever ...).
So I pursued this idea by having each control have it's own texture/canvas in order not to draw more than I have to.
I do tend to try and optimize here and there =P perhaps a little quirk of mine ...

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.

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!