OpenGL level editor problem ??

OpenGL level editor problem ??

Post by Jose J. Sanche » Fri, 10 Jan 2003 04:53:03



Hi, i'm trying to build a game editor and have the following problem.

you know how in any 3D level editor lets you create cubes, boxes, spheres,
ok, thats easy, but what about when in the level editor you can select any
object on the scene and change it's attributes, thats my problem, HOW CAN I
SELECT AN OBJECT IN A 3D SCENE BASED ON A 2D MOUSE POSITION.

if i have 3 cubes: one left, one right and one in the middle of the 2D
screen and the user clicks over the left cube, how am i able to say "the
left cube is the selected object"

I hope i made it clear, and if anybody can help it will be GREATLY
appreciated.

Thanks again,

Jose Sanchez

 
 
 

OpenGL level editor problem ??

Post by Luke Parson » Fri, 10 Jan 2003 11:29:27


Uhm hehee.. here's my limited knowledge again.. but if you think about it,
if your Mouse is in 2D space (ie. X and Y) then anything under the mouse is
along its Z axis. Just "search" for an object along that Z-axis line until
you hit an object. Ofcourse you'll have to go "forwards" away from the mouse
rather than "behind" your view but ultimately the Z-axis is infinite in the
"forward" direction, as infinite as your viewing distance allows that is.



Quote:> Hi, i'm trying to build a game editor and have the following problem.

> you know how in any 3D level editor lets you create cubes, boxes, spheres,
> ok, thats easy, but what about when in the level editor you can select any
> object on the scene and change it's attributes, thats my problem, HOW CAN
I
> SELECT AN OBJECT IN A 3D SCENE BASED ON A 2D MOUSE POSITION.

> if i have 3 cubes: one left, one right and one in the middle of the 2D
> screen and the user clicks over the left cube, how am i able to say "the
> left cube is the selected object"

> I hope i made it clear, and if anybody can help it will be GREATLY
> appreciated.

> Thanks again,

> Jose Sanchez


 
 
 

OpenGL level editor problem ??

Post by Dubuisson Moniqu » Fri, 10 Jan 2003 14:13:34


Hi,

With opengl, you can use the functions 'glRenderMode(GL_SELECT)' and
'glLoadName' to select objects in a scene.
Or the function 'glUnproject' to get the 3D coordinates relative to a point
on the screen.



Quote:> Hi, i'm trying to build a game editor and have the following problem.

> you know how in any 3D level editor lets you create cubes, boxes, spheres,
> ok, thats easy, but what about when in the level editor you can select any
> object on the scene and change it's attributes, thats my problem, HOW CAN
I
> SELECT AN OBJECT IN A 3D SCENE BASED ON A 2D MOUSE POSITION.

> if i have 3 cubes: one left, one right and one in the middle of the 2D
> screen and the user clicks over the left cube, how am i able to say "the
> left cube is the selected object"

> I hope i made it clear, and if anybody can help it will be GREATLY
> appreciated.

> Thanks again,

> Jose Sanchez

 
 
 

OpenGL level editor problem ??

Post by DM » Fri, 10 Jan 2003 14:30:57


Exemple of use
http://ask.ii.uib.no/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/ (The
red book - chapter 13).



> Hi,

> With opengl, you can use the functions 'glRenderMode(GL_SELECT)' and
> 'glLoadName' to select objects in a scene.
> Or the function 'glUnproject' to get the 3D coordinates relative to a
point
> on the screen.




> > Hi, i'm trying to build a game editor and have the following problem.

> > you know how in any 3D level editor lets you create cubes, boxes,
spheres,
> > ok, thats easy, but what about when in the level editor you can select
any
> > object on the scene and change it's attributes, thats my problem, HOW
CAN
> I
> > SELECT AN OBJECT IN A 3D SCENE BASED ON A 2D MOUSE POSITION.

> > if i have 3 cubes: one left, one right and one in the middle of the 2D
> > screen and the user clicks over the left cube, how am i able to say "the
> > left cube is the selected object"

> > I hope i made it clear, and if anybody can help it will be GREATLY
> > appreciated.

> > Thanks again,

> > Jose Sanchez

 
 
 

OpenGL level editor problem ??

Post by Eric Grang » Sat, 11 Jan 2003 01:15:08


The OpenGL picking mechanism can do that, see the 'pick' example at

        http://www.delphi3d.net/listfiles.php?category=7

I also have some picking demos wrapped along with the other
GLScene demos.

Eric Grange
http://glscene.org

 
 
 

OpenGL level editor problem ??

Post by john hutching » Sat, 11 Jan 2003 03:27:44


Really what you are dealing with is a scene graph.  You want to be able to
interactively build the scene graph using both the scene itself and the node
tree.  This is the approach taken by SGI (Open Inventor) and derivatives (eg
Cosmo Player).

If you are really serious then take a look at 3DShapes Pro
(www.datavis.com.au) which the pick functionality built in.

John Hutchings
DataVis



Quote:> Hi, i'm trying to build a game editor and have the following problem.

> you know how in any 3D level editor lets you create cubes, boxes, spheres,
> ok, thats easy, but what about when in the level editor you can select any
> object on the scene and change it's attributes, thats my problem, HOW CAN
I
> SELECT AN OBJECT IN A 3D SCENE BASED ON A 2D MOUSE POSITION.

> if i have 3 cubes: one left, one right and one in the middle of the 2D
> screen and the user clicks over the left cube, how am i able to say "the
> left cube is the selected object"

> I hope i made it clear, and if anybody can help it will be GREATLY
> appreciated.

> Thanks again,

> Jose Sanchez

 
 
 

OpenGL level editor problem ??

Post by Luke Parson » Sat, 11 Jan 2003 10:42:31




Quote:> What if i'm looking up, down, or am not just simply along the X axis,
> remember it's 3D space and i can rotate the camera and translate it to any
> given position and degrees,

Sorry I meant in relation to the X and Y of the mouse. The mouse will always
be X and Y in its "own" 2D space. So just as the infinite Z-axis relies on
the view distance, the Z-axis of the mouse relies on the rotating of the
"camera".

Sorry, I'm just throwing ideas around.. :)

 
 
 

OpenGL level editor problem ??

Post by AndrĂ© di Geronim » Sat, 11 Jan 2003 21:38:41


Quote:> you know how in any 3D level editor lets you create cubes, boxes, spheres,
> ok, thats easy, but what about when in the level editor you can select any
> object on the scene and change it's attributes, thats my problem, HOW CAN
I
> SELECT AN OBJECT IN A 3D SCENE BASED ON A 2D MOUSE POSITION.

When I wrote a 3D editor a few years ago I faced the same problem. I ended
up
mapping the 3D object coordinates to window coordinates with gluProject()
and
then check those against the mouse coordinates. I dont have that code
accessible right now so unfortunately I cant give a you a working example.

Regards,
Andr di Geronimo

 
 
 

OpenGL level editor problem ??

Post by Ananth B » Wed, 12 Feb 2003 17:08:14


Hi Jose,

Here is a code snippet I wrote for a previous project, this does not use
hierarchical picking, but I'm sure with a few changes it could easily be
adapted for that.

function TfrmMain.ObjectUnderMouse(X, Y: integer; aScene: TScene):
TBaseObject;
var
  viewport: array[0..3] of glint;
  SelectionBuffer: array[0..512 - 1] of gluint;
  hits: integer;
  realY: integer;
  i: integer;

begin
  result := nil;


  realY := viewport[3] - Y - 1 - pnlOGL.Top;

  glRenderMode(GL_SELECT);
  glInitNames;
  glPushName(0);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPickMatrix(X, realY, PICK_WIDTH, PICK_HEIGHT,
TViewportArray(viewport));

  gluPerspective(FCamera.ViewVolume.FOV,
    FCamera.ViewVolume.Width / FCamera.ViewVolume.Height,
    FCamera.ViewVolume.Hither,
    FCamera.ViewVolume.Yon);

  FCamera.SetViewOnly; // this does not set the projection matrix, only the
modelview
  aScene.RenderToFeedback; // This renders all the objects with a glLoadName
call

  hits := glRenderMode(GL_RENDER);

  if hits >= 1 then
  begin
    for i := 0 to aScene.ObjectCount - 1 do
      if aScene.Objects[i].ID = SelectionBuffer[3] then // the ID is a
unique gluint assigned to each object when created
      begin
        result := aScene.Objects[i];
        break;
      end;
  end;
end;

Hope this helps,

Regards,
Ananth B.



> What if i'm looking up, down, or am not just simply along the X axis,
> remember it's 3D space and i can rotate the camera and translate it to any
> given position and degrees,

> I've looked into it a little bit, and they told me to use glRenderMode,
> glInitName and gluPushMatrix but haven't been able to make it work so if
> anybody know how I would GREATLY appreciate a code sample



> > Uhm hehee.. here's my limited knowledge again.. but if you think about
it,
> > if your Mouse is in 2D space (ie. X and Y) then anything under the mouse
> is
> > along its Z axis. Just "search" for an object along that Z-axis line
until
> > you hit an object. Ofcourse you'll have to go "forwards" away from the
> mouse
> > rather than "behind" your view but ultimately the Z-axis is infinite in
> the
> > "forward" direction, as infinite as your viewing distance allows that
is.



> > > Hi, i'm trying to build a game editor and have the following problem.

> > > you know how in any 3D level editor lets you create cubes, boxes,
> spheres,
> > > ok, thats easy, but what about when in the level editor you can select
> any
> > > object on the scene and change it's attributes, thats my problem, HOW
> CAN
> > I
> > > SELECT AN OBJECT IN A 3D SCENE BASED ON A 2D MOUSE POSITION.

> > > if i have 3 cubes: one left, one right and one in the middle of the 2D
> > > screen and the user clicks over the left cube, how am i able to say
"the
> > > left cube is the selected object"

> > > I hope i made it clear, and if anybody can help it will be GREATLY
> > > appreciated.

> > > Thanks again,

> > > Jose Sanchez

 
 
 

1. OpenGL using VB5? (for object editor/level editor)

Has anyone tried using OpenGL from Visual Basic?

I thought this would be an ideal way to create a simple object editor/level
editor with a nice GUI in a lot less time that it would take me using Win32
C++ (or even Visual C++ with MFC)

It should work, as all I need to do is call functions in OpenGL32.dll and
Glu32.dll, and I know VB has a function to retreive the HWND of a form

Has anyone tried this? Is there any sample code around?

=====-===-==-=-=--=--- -- -
David M.Reed

Web: www.highframerate.freeserve.co.uk
ICQ: 27301764
=====-===-==-=-=--=--- -- -

2. Triangle Picking

3. OpenGL Level Editor

4. HTML buttons, how to fade transparent instead of white.

5. new free 3d-editor + sources + small levels

6. Looking for Sun 386i modifications to pbm...

7. Editor on pixel level? (SGI)

8. Most Lightwave Friendly Game Map/Level Editor.

9. New sprite/level editor: Tile Studio

10. heightfield / level editor

11. Level editor

12. Grid in a Level Editor