A great game hit a bottomless pit

Originally posted by Doug:
See the source to the smooth.c demo in the GLUT distribution for an example of doing this using gluProject and gluUnproject (in the mouse and move methods).

I tried this code, but the 2d point never rendered to anything near my selection in 3D. … I’m pretty frustrated with the whole thing…

Your telling me. Try using a system of angles.

The best way to select objects is:
draw all your objets in the back buffer,
each one with a different color, then
you have only to compare the color of
the pixel where the mouse is with the
color of your objects. If you are working
at 32-lebel depth, as usuall, a single
scan of your image lets you choose between
65,000 objects, if you need more you need
to scan again. Of course you do this in the back buffer so the user doesn’t see nothing.This method is very simple, very elegant and very powerfull, it will work always as long as you draw the scene EXACTLY in the same way, when you are showing it and when you are picking objects. It is mentioned in the advanced methods, in the last chapter of the oficial red book. I implemented this
method in my GNU/Linux application, where the number of objects can easily be several thousands, and where I have 17 different classes of objects, which makes things even more complex, so I really know what I am talking about :wink:

I don’t mean to be offensive or anything, but I’ve already explained many times that the problem is not the picking so much as the click & drag which is essential.

Dragging using your technique would be far from efficient.

Carlos:

I don’t think that is a very efficient way of doing it.

I still think the feedback buffer is the best bet.

[This message has been edited by Blaze (edited 09-09-2000).]

What’s wrong with this code? This is part of my camera positioning code for the freelook.
It translates the camera to the ship’s coordinate that the camera’s orbiting, and if they want to look around freely then it goes to oberver mode 1.
Here I project out the zoom line so I end up with the camera’s 3d coordinate and can feely look around.

There’s something wrong with my trig here.

void RenderCamera()
{
if (Mcamera.zoom<10)
Mcamera.zoom=10;

if (Mcamera.zoom&gt;80)
	Mcamera.zoom=80;

if (Mcamera.xangle&gt;90)
	Mcamera.xangle=90;

MoveShips();
// if Camera has new target and hasn't acquired approp. position
if (Mcamera.ctargetstep&lt;10)
{
	Mcamera.x+=Mcamera.cx;
    Mcamera.y+=Mcamera.cy;
	Mcamera.z+=Mcamera.cz;
	Mcamera.ctargetstep+=1;
}
else
{  
	Mcamera.x=ship[Mcamera.target].x;
	Mcamera.y=ship[Mcamera.target].y;
	Mcamera.z=ship[Mcamera.target].z;
}

float tx,ty,tz;

tx=Mcamera.x;
ty=Mcamera.y;
tz=Mcamera.z;

Mcamera.vx=((float)cos(Mcamera.yangle) * Mcamera.zoom)+ship[Mcamera.target].x;
//Mcamera.vz=((float)sin(Mcamera.yangle*piover180) * Mcamera.zoom)+ship[Mcamera.target].z;
Mcamera.vz=((float)sin(Mcamera.yangle) * Mcamera.zoom)+ship[Mcamera.target].z;
float ux=Mcamera.xangle;
if (ux&gt;360) 
	ux-=360;
if (ux&lt;0)
	ux+=360;

float t=(cos (ux)*180);

Mcamera.vy=((float)t * Mcamera.zoom)+ship[Mcamera.target].y;


if (!Observer)
{
	glTranslatef(-tx,-ty,-tz);
	glTranslatef(0,0,-Mcamera.zoom);
    // Camera Looking Around

	glRotatef(Mcamera.xangle,1.0f,0.0f,0.0f);
    glRotatef(Mcamera.yangle,0.0f,1.0f,0.0f);	
    //sprintf(str, "Orbit x: %f y: %f",Mcamera.xangle,Mcamera.vy);

}

if (Observer)
{
	  glRotatef(Mcamera.vxangle,1,0,0);
	  glRotatef(Mcamera.vyangle,0,1,0);
	  //glTranslatef(Mcamera.vx,-Mcamera.vy,-Mcamera.vz);
	  //glTranslatef(-tx,-ty,-(tz-Mcamera.zoom));
	  glTranslatef(Mcamera.vx,-Mcamera.vy,-Mcamera.vz);

}

}

Sorry NEVER MIND THAT CODE PEOPLE
don’t reply to that one.

That code was all wrong from a different version. Here’s the real stuff:

void RenderCamera()
{
if (Mcamera.zoom<10)
Mcamera.zoom=10;

if (Mcamera.zoom&gt;80)
	Mcamera.zoom=80;

if (Mcamera.xangle&gt;90)
	Mcamera.xangle=90;

MoveShips();
// if Camera has new target and hasn't acquired approp. position
if (Mcamera.ctargetstep&lt;10)
{
	Mcamera.x+=Mcamera.cx;
    Mcamera.y+=Mcamera.cy;
	Mcamera.z+=Mcamera.cz;
	Mcamera.ctargetstep+=1;
}
else
{  
	Mcamera.x=ship[Mcamera.target].x;
	Mcamera.y=ship[Mcamera.target].y;
	Mcamera.z=ship[Mcamera.target].z;
}

float tx,ty,tz;

tx=Mcamera.x;
ty=Mcamera.y;
tz=Mcamera.z;

Mcamera.vx=((float)sin(Mcamera.yangle*piover180) * Mcamera.zoom)+ship[Mcamera.target].x;
//Mcamera.vz=((float)sin(Mcamera.yangle*piover180) * Mcamera.zoom)+ship[Mcamera.target].z;
Mcamera.vz=((float)cos(Mcamera.yangle*piover180) * Mcamera.zoom)+ship[Mcamera.target].z;
float ux=Mcamera.xangle;
if (ux&gt;360) 
	ux-=360;
if (ux&lt;0)
	ux+=360;

 float t=(sin (ux)*piover180);

Mcamera.vy=((float)sin(Mcamera.xangle*piover180)*Mcamera.zoom)+ship[Mcamera.target].y;

sprintf(str,"%f",sin(Mcamera.xangle*piover180));

if (!Observer)
{
	glTranslatef(-tx,-ty,-tz);
	glTranslatef(0,0,-Mcamera.zoom);
    // Camera Looking Around

	glRotatef(Mcamera.xangle,1.0f,0.0f,0.0f);
    glRotatef(Mcamera.yangle,0.0f,1.0f,0.0f);	
    //sprintf(str, "Orbit x: %f y: %f",Mcamera.xangle,Mcamera.vy);

}

if (Observer)
{
	  glRotatef(Mcamera.vxangle,1,0,0);
	  glRotatef(Mcamera.vyangle,0,1,0);
	  //glTranslatef(Mcamera.vx,-Mcamera.vy,-Mcamera.vz);
	  //glTranslatef(-tx,-ty,-(tz-Mcamera.zoom));
	  glTranslatef(Mcamera.vx,-Mcamera.vy,-Mcamera.vz);

}

}

Dragging is an entirely different matter than picking. I do use dragging to move, rotate and scale my objects, but unless you use OpenGL alone, this tends to be done using some sort of Toolkit like Motif/Lesstif, GTK,
Tcl/Tk, QT. I am sure in Windows things are not all that different. If you use a drawing area widget this is the way to do that. Of course then you have to build your own engine, in dynamic memory, etc…

About the efficiency of the picking method I described above, I am not sure that people understood what I said: In picking mode, all
objects are drawn at the same time, but each one with a different color, so you can distinguish them. If your scene draws at
say 20fps, then you pick your object in about 1/20 sec. Note that for example depth problems are automatically solved because objects which are underneath will be hidden and cannot be picked. You can have (I do) complex lightning, you can have any texture mapping, etc… Of course you need to
disable them (dithering also, for obvious reasons) in picking mode, which makes things even faster.

If your program is simple, feedback
or standard selection techniques can
be used, but if you have something more
complex, with many different objects and matrix transformations, this is really the simplest 100% reliable way to select objects!
See Red Book, pg 389.

I’d be glad to use that picking method. OpenGL’s selection buffer works well for simple selecting. But honestly, for a game that appears something like homeworld, do you actually think you’ll be able to play the game without dragging?
100+ships on the screen?

I’m using selection like so:
Instead of using mouse pointer, the viewer moves the whole camera with the selection cursor in the middle of the screen.
Then the engine compares the angle of the camera to a ship to see if it’s the same angle that the viewer clicked at. It’s a very very simple concept.
I have a very simple trig problem here it seems. I’m using both COS and SIN and they are mixed up. When I rotate the camera up, then go to observer mode like so, the camera’s location changes and that’s not supposed to happen.

Please somebody take a look at the code and tell me what’s not right.