Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Daivuk

Selecting unit in 3d.

This topic is 5525 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 there. I''m creating a game like starcraft but all in 3d. Now I have my units (openGL display list for the models) and draw it on my 3d terran. But, my mouse on the screen I have it in 2d. 0 to 640 and 0 to 480. This is for the mouse. So, there is a function in opengl that can return me the 2d value on the screen of a 3d point ??? Because I really dont know how I will proced... :''( so, help me, thanks

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
quote:
Original post by Daivuk
and draw it on my 3d terran.



I think this person has been playing too much StarCraft

Share this post


Link to post
Share on other sites
create a bounding box for the unit and transfor the mouse coords into 3d space and do an interscet triangle on all the tri''s that make the bounding box exactly like the pick example in the directx sdk i dont know the equivelant functions for gl tho

Share this post


Link to post
Share on other sites
ouch... 1650 units.. hum..
Looking for a openGl function like
glFeedbackBuffer
that can return information about your drawing... I just dont understand how it work...

Share this post


Link to post
Share on other sites
I know about picking, but its not what I want.. When I draw my units on the screen, for each I want to know if my mouse is over it. Not over the model, but Over a square around it. Square in 2D. So the only thing I want, its if I draw a point in 3d (x,y,z), where it will be draw on the screen? in the frame buffer for example, where it will be positioned in 2d this point ? After I know all to do the rest of the shit.
There is probably a function in ogl return it! Because it use something like that to draw my point in the frame buffer.

Share this post


Link to post
Share on other sites
I use this function, for my game:

  
void get_world_x_y()
{
float window_ratio;
float x,y,x1,y1,a,t;
window_ratio=(GLfloat)window_width/(GLfloat)window_height;

x=(float)(mouse_x*9.0f/window_width)-(9.0f/2.0f);
y=(float)((window_height-mouse_y)*6.0f/window_height)-(6.0f/2.0f);

a=(rz)*3.1415926/180;
t=(rx)*3.1415926/180;

y=y/cos(t);

x1=x*cos(a)+y*sin(a);
y1=y*cos(a)-x*sin(a);


scene_mouse_x=-cx+x1;
scene_mouse_y=-cy+y1;



rx, and ry are the rotation on the x and z axis. But I have my axes inverted (Z points up), so you might want to change that...

Hope it helps.

P.S. This function assumes a 2/3 window ratio, and an ortho projection...

Height Map Editor | Eternal Lands | Fast User Directory

Share this post


Link to post
Share on other sites
if u have a top view of the world then it''s simple
for a unit u have a vPos vector. find out if the MouseX and MouseY are inside square (vPos.x - MapX, vPos.y - mapY) - (vPos.x - mapx + width_of_square, vpos.y - mapy + height_of_sq)

if u have an isometric view its harder
project the units onto the view plane and also use somethin like a z-buffer then do the mouse in square test

/*ilici*/

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!