How to draw cross hair cursor in opengl while rotating camera ??
-
Hi, I am displaying 3D models using opengl and VC++. I have implemented code to rotate, move, zoom the model by moving camera (using gluLookAt() ) Now I want to add one cross hair cursor in front of camera view port(at center of screen), but when I tried to rotate or zoom the model the cursor also rotates or zoom along with model. How I can make cursor lie at same position while rotating model. Please help me :((
-
Hi, I am displaying 3D models using opengl and VC++. I have implemented code to rotate, move, zoom the model by moving camera (using gluLookAt() ) Now I want to add one cross hair cursor in front of camera view port(at center of screen), but when I tried to rotate or zoom the model the cursor also rotates or zoom along with model. How I can make cursor lie at same position while rotating model. Please help me :((
After you are done rendering the rest of the scene, reset your view matrix and projection matrix to width and height of your screen and with and ortho projection. Then Draw your cross hair in the center. It does not have to exist in world space. Basically, it is a HUB display on the near plan of your view.
ARon
-
After you are done rendering the rest of the scene, reset your view matrix and projection matrix to width and height of your screen and with and ortho projection. Then Draw your cross hair in the center. It does not have to exist in world space. Basically, it is a HUB display on the near plan of your view.
ARon
But I want to do only rotation on cursor (it is same as three unit axes rotates about one fixed point) which was done on entire 3d model but to avoid pan and zoom operations. How to do this ???
-
But I want to do only rotation on cursor (it is same as three unit axes rotates about one fixed point) which was done on entire 3d model but to avoid pan and zoom operations. How to do this ???
I not sure what you are trying to do but this is how I draw an object(s) in space. Forgive me it I c#.
static public void RenderScence()
{
Object LockThis = new Object();
lock (LockThis)
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);#region Draw Scene From Camera View #region Set the Current Camera Matrix // Get the Current Cameras View Transform and Load it in to OpenGl Projection Matrix Matrix\_44 HTotal = CurrentCamera.HTotal; Gl.glMatrixMode(Gl.GL\_PROJECTION); Gl.glLoadIdentity(); // Then I clear the ModelView Matrix as it is overriden by each Drawable Object Gl.glLoadMatrixf(HTotal.GetListValues()); Gl.glMatrixMode(Gl.GL\_MODELVIEW); Gl.glLoadIdentity(); #endregion // Draw each visible object foreach (ISpatialNode obj in WorldObjectList) if (obj.IsVisible) obj.RenderOpenGL(); #endregion Gl.glFinish(); } }
Base on your description I would create a crosshair class and maintain it orientation and position in the world. When it is time to render the crosshair I would just loaded its Position and Rotation in to the ModelView matrix and then draw it as if it were in free space. References. My article on transforms easily adapted to c++. Space and Matrix Transformations - Building a 3D Engine[^] Others probably better Interactive Techniques in Three-dimensional Scenes (Part 1): Moving 3D Objects with the Mouse using OpenGL 2.1[^] A New Perspective on Viewing[^] Arcball Module in C# - Tao.OpenGL[^]
-
I not sure what you are trying to do but this is how I draw an object(s) in space. Forgive me it I c#.
static public void RenderScence()
{
Object LockThis = new Object();
lock (LockThis)
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);#region Draw Scene From Camera View #region Set the Current Camera Matrix // Get the Current Cameras View Transform and Load it in to OpenGl Projection Matrix Matrix\_44 HTotal = CurrentCamera.HTotal; Gl.glMatrixMode(Gl.GL\_PROJECTION); Gl.glLoadIdentity(); // Then I clear the ModelView Matrix as it is overriden by each Drawable Object Gl.glLoadMatrixf(HTotal.GetListValues()); Gl.glMatrixMode(Gl.GL\_MODELVIEW); Gl.glLoadIdentity(); #endregion // Draw each visible object foreach (ISpatialNode obj in WorldObjectList) if (obj.IsVisible) obj.RenderOpenGL(); #endregion Gl.glFinish(); } }
Base on your description I would create a crosshair class and maintain it orientation and position in the world. When it is time to render the crosshair I would just loaded its Position and Rotation in to the ModelView matrix and then draw it as if it were in free space. References. My article on transforms easily adapted to c++. Space and Matrix Transformations - Building a 3D Engine[^] Others probably better Interactive Techniques in Three-dimensional Scenes (Part 1): Moving 3D Objects with the Mouse using OpenGL 2.1[^] A New Perspective on Viewing[^] Arcball Module in C# - Tao.OpenGL[^]
Thanks for ur reply. I have tried to reset the modelview matrix and projection matrix and I am successful to display axes 90 percent, the remaining problem is that while rotating the 3d model flickers (at start zoom - in and at end at normal size and position). I have tried this code after finishing of rest 3d model drawing :
glMatrixMode(GL_PROJECTION);
glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);
glLoadIdentity(); // reset projection matrixGLdouble gldAspectRatio = (GLdouble) ViewportSize.right/(GLdouble) ViewportSize.bottom;
glOrtho ( pViewVolumeAxe[0], pViewVolumeAxe[1],
pViewVolumeAxe[2]/gldAspectRatio,
pViewVolumeAxe[3]/gldAspectRatio,
pViewVolumeAxe[4], pViewVolumeAxe[5] );glMultMatrixd(projMatrix);
glMatrixMode(GL_MODELVIEW);
glGetDoublev (GL_MODELVIEW_MATRIX ,modelMatrix);
glLoadIdentity(); // reset model view matrix// do reverse translation as to keep axes at same position
glTranslated(-modelMatrix[12], -modelMatrix[13], -modelMatrix[13]);glMultMatrixd(modelMatrix);
// translate whole setup to model center currently I am // displaying at origin(0,0,0)
glPushMatrix();
glTranslatef(fXTrans, fYTrans, fZTrans);// then all axes draw stuff
-
Hi, I am displaying 3D models using opengl and VC++. I have implemented code to rotate, move, zoom the model by moving camera (using gluLookAt() ) Now I want to add one cross hair cursor in front of camera view port(at center of screen), but when I tried to rotate or zoom the model the cursor also rotates or zoom along with model. How I can make cursor lie at same position while rotating model. Please help me :((
To create a crosshair cursor that remains fixed at the center of the viewport while allowing your 3D model to rotate and zoom, you'll need to render the crosshair after the 3D scene is drawn, but before you swap buffers or display the result. Here’s how you can achieve this: Step-by-Step Approach Render the 3D Scene: Continue using your current camera transformations (like gluLookAt()) to render the 3D model. Set Up the 2D View for the Crosshair: After rendering the 3D scene, switch to orthographic projection mode for rendering the crosshair. Use glMatrixMode(GL_PROJECTION) and glLoadIdentity() to set up the orthographic projection. Set the view volume using glOrtho(). Draw the Crosshair: Once in the orthographic projection mode: Set the color and draw the crosshair at the center of the screen. Use glBegin() and glEnd() to create lines or a texture for the crosshair. Return to the 3D View: After drawing the crosshair, switch back to the perspective projection to prepare for the next frame. Jazimo