Advertisement

Drawing a 3D mouse cursor

Started by October 21, 2004 02:53 PM
2 comments, last by bartkiller 20 years, 1 month ago
Hello, i have an annoying problem. I'm using the procedure from NeHe's tutorials, which converts window coordinates to OpenGl coordinates - works cool. I have a display list, which draws the mouse cursor : glNewList(ListID,GL_COMPILE); glBegin(GL_QUADS); glVertex3f(0,t/2,t/2); glVertex3f(0,-1*t/2,t/2); /* ....... */ glVertex3f(h,-1*t/2,-1*t/2); glVertex3f(h,t/2,-1*t/2); glEnd(); glBegin(GL_TRIANGLES); glVertex3f(h*4/5,t*9/10,t*9/10); glVertex3f(h*4/5,t*-9/10,t*9/10); glVertex3f(h*5/4,0,0); /* .... */ glEnd(); glEndList(); It's a 3D arrow, and I want it to point towards the screen, and to be rotated round the x-axis to look 'isometrically cool' ;) So, in the Draw function i do the following : glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); C1.Update(); /* Update camera */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45,(float)W/(float)H,0.1,100.0); gluLookAt(C1.Location.x,C1.Location.y,C1.Location.z, C1.Target.x,C1.Target.y,C1.Target.z, C1.Up.x,C1.Up.y,C1.Up.z); /* Draw object(s) */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); G1->Pokaz(); /* Pokaz means Show in Polish ;) */ /* HERE i'm trying to draw the cursor : */ glLoadIdentity(); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glColor3f(1,1,1); /* Thats the function from NeHe's tutorials */ GetGLPos(mouse.x,mouse.y,&mousex,&mousey,&mousez); glTranslated(mousex,mousey,mousez); glTranslatef(0,0,10); glRotatef(130,0,1,0); glRotatef(55,1,0,0); glTranslatef(-8,0,0); Mysz->Pokaz(); /* Mysz means Mouse in Polish ;) */ glDisable(GL_COLOR_MATERIAL); And i experience such a problem : when the cursor moves on the screen it's seen from different angles :/ if i try to draw it before setting the projection matrix, before drawing object, with other projection matrix it doesnt work or the effect is the same :/ please someone help me !!! how to do it, without rotating the cursor depending on its position ? (and without rendering to texture - thats to hard for me )
I think I understand what your talking about, I belive your problem is caused by gluPerspective, if you want something 3d to appear the same no matter what Position(corrected), its seen from, it must be drawn in glOrtho projection matrix, maybe that can help? look into it.

Edit: reworded, sentence

[Edited by - Xero-X2 on October 21, 2004 10:09:45 PM]
"I seek knowledge and to help those who also seek it"
Advertisement
thanks for the advice.

unfortunately, when i tried gluOrtho2d(-1,1,-1,1);

i couldnt see the cursor at all :/

i'll try some more with it
my mistake :D

the correct answer was ofcourse : glOrtho(0,W,0,H,0.1,100.0);

(W window width, H window height)

thank You once again !

This topic is closed to new replies.

Advertisement