PDA

View Full Version : Need Suggestions on Screen co-ordinate system



chethan
05-10-2012, 06:47 AM
Hi
go thru this screen co-ordinate creation snippet :


// CMFC_View drawing in MFC.
void CMFC_View::OnDraw(CDC* pDC)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//if(m_3D)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
////select the viewing volume
if(perspectView)
{
gluPerspective(26.0f, aspect_ratio, 1.0f, 10000.0f);
gluLookAt(0.0f,0.0f,m_width*2,0.0f,0.0f,0.0f,0.0f, 1.0f,0.0f);
} else {
glOrtho(-1*m_width,m_width,-1*m_height,m_height,-1*1000,1000);
}//// switch back to the modelview matrix and clear it
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GetGLMat(m); //Creates 16 elements for Transformations and holds the data.
glMultMatrixf(m); // Multiplies to the MODELVIEW matrix for changes in display.
glPushMatrix();
DisplayGL();
glPopMatrix();
glFlush();
SwapBuffers(m_pDC->GetSafeHdc());
}


My questions are
1. I am creating a orthognal viewport is this good for Modification of vertices in world screen?
2. If yes give me suggestions on how to modify the Vertices in world screen after transformations?
3. If any other formats to control world screen co-ordinate system, welcome?

thokra
05-10-2012, 07:02 AM
First, a few notes:

a) Please put your snippet into a '['code']' your code here '['/code']' section. Also, you should read the forum guidelines since asking people to read through code in the way you do above isn't really that polite.
b) Second, what the hell is a world screen? You are either in world coordinates or in screen coordinates.
c) I can't see any line of code setting up a viewport. Do you understand what a viewport is? Do you mean the view frustum?
d) I really don't know what your 3. question is supposed to mean.

chethan
05-10-2012, 10:41 PM
I apologize for this post kind. I am a new to this so I did mistake forgive me sorry again. I am trying to explain I have a viewport of ortho so during rotation,scale I am facing problem. The 3D object rotates with respective center of its axis when Z=0. when Z changes the center of rotation not going to happen so my question is how to make world transformations and local transformations of screen co-ordinate system. If you know please tell me that so I can adopt to ma code.

thanks and regards
9max9

thokra
05-11-2012, 03:35 AM
I have a viewport of ortho[..]

The viewport has nothing to do with the current projection matrix. The viewport is simply a 2D subset of the framebuffer and is used to map vertices from normalized device coordinates to the screen. What you're talking about is an orthogonal projection, glOrtho takes arguments describing the planes of the view-frustum which affects projection of vertices to clip coordinates.


how to make world transformations and local transformations of screen co-ordinate system..

The screen coordinate system has nothing to do with rotating objects in object- or world-space. You can reconstruct world-space positions from screen space with additional information but that's not what you're going for.

As far as I get it you're simply trying to rotate an object locally. So you want some object to always rotate about a certain axis, independent of its world-space position. Is that correct?

V-man
05-12-2012, 08:46 AM
My questions are
1. I am creating a orthognal viewport is this good for Modification of vertices in world screen?
2. If yes give me suggestions on how to modify the Vertices in world screen after transformations?
3. If any other formats to control world screen co-ordinate system, welcome?

1. it is fine.
2. You transform all the vertices from object space to screen space using gluProject. Check to see which vertex is closest to the mouse. Select that vertex. As the mouse moves, move the vertex.
3. You mean other projections? You can try in perspective space if you are up to it.

BTW : don't call gluLooktAt on a perspective matrix. It will mess up your lighting and certain texgen modes.