Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (755)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Projection Question  (Read 2523 times)
0 Members and 1 Guest are viewing this topic.
Offline Middy

Junior Devvie




Java games rock!


« Posted 2004-11-08 15:35:14 »

This might be a dumb question. But here it goes. How would I project a 3D object to a place in screen coordinates?



When do I get my makeMyGameAsILike() extension?
Offline Chman

Junior Devvie




Nothing more that... Java games are cool !


« Reply #1 - Posted 2004-11-08 15:41:25 »

I would be pleased to answer your question, but I don't really understand it... Can you be more specific ? What do you want to achieve with this ?

Chman
Offline Middy

Junior Devvie




Java games rock!


« Reply #2 - Posted 2004-11-08 15:45:19 »

Well  I am doing a 3D scanner. Shows other objects relative position to whoever owns the scanner.

The scanner is a sphere with red blips inside of it. I would like to put this sphere say in lower right corner of the screen as a part of the HUD.

When do I get my makeMyGameAsILike() extension?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Chman

Junior Devvie




Nothing more that... Java games are cool !


« Reply #3 - Posted 2004-11-08 15:57:01 »

Well, if I understand correctly, I would proceed like that :

- Get wanted objects coordinates (the ones to display on the scanner) in 3d space (x,y,z).

- Get the length of the clip pane of the current frustrum.

- Create the scanner sphere with a diameter of 1 unit (as example).

- Create a virtual sphere with a radius of max_clip_frustrum centered on the player location.

- For every ships (or what you want them to be), check if it's in the sphere frustrum. If not, it won't be visible in the scanner. Else, for each ship, divide the scanner diameter byt the (x,y,z) ship values.

You should get your ship position in scanner... I think it should work (I'm very very very tired, insomniac, so maybe my suggestion is a little dumb Embarrassed...).

Chman Smiley
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #4 - Posted 2004-11-08 16:09:47 »

You could use Ortho mode.  It is only parallel projection, but it should be sufficient for what you want to do.
1  
2  
3  
4  
5  
6  
GL11.glPushMatrix(GL11.GL_PROJECTION);
GL11.glOrtho(0,800,600,0,-1.0,1.0);
GL11.glLoadIdentity();
GL11.glTranslate(700,500,0);
//draw object
GL11.glPopMatrix(GL11.GL_PROJECTION);

This may no be perfect, but you get the idea.

What ever numbers you specify in glOrtho command will give you the screen coordinates that you can use.

Offline Middy

Junior Devvie




Java games rock!


« Reply #5 - Posted 2004-11-08 16:38:41 »

Not sure I get what you mean chman but i'll ponder over it.

The scanner works with a range in world units. Everything within that range has a red dot. I am just checking range every update from this object to all others, may be ineffecient. But I have only one scanner and perhaps 10-20 objects checked every 0.5 sec.

I am realy looking for a way to render that 3D sphere in a nice GUI/HUD manner without using ortho :-(

CaptainJester I tried using ortho it looks like well.. a parallel projection.

When do I get my makeMyGameAsILike() extension?
Offline Middy

Junior Devvie




Java games rock!


« Reply #6 - Posted 2004-11-08 19:53:13 »

Okay been reading up Chman and trying to understand.


Quote

- Get wanted objects coordinates (the ones to display on the scanner) in 3d space (x,y,z).

Sure done

Quote

- Get the length of the clip pane of the current frustrum.

front or back clipping plane?

Quote

- Create the scanner sphere with a diameter of 1 unit (as example).

sure sure

Quote

- Create a virtual sphere with a radius of max_clip_frustrum centered on the player location.

Virtual sphere whats that?

Quote

- For every ships (or what you want them to be), check if it's in the sphere frustrum. If not, it won't be visible in the scanner. Else, for each ship, divide the scanner

Well i stated another method to check if they are within scan range, but this could be faster?

My main problem is to render a sphere as a HUD, just a 3D one.





When do I get my makeMyGameAsILike() extension?
Offline Chman

Junior Devvie




Nothing more that... Java games are cool !


« Reply #7 - Posted 2004-11-08 20:46:57 »

Quote
front or back clipping plane?

Frnot, because you must get the farest point that the player can see.

Quote
Virtual sphere whats that?

I must admit that I am not very good at explanations Tongue ! A virtual sphere would just be a center point and a radius (radius = front clipping plane). This sphere would not be drawn, you'd just keep it in memory and use it to test is ships are in the scanner area or not...

Quote
Well i stated another method to check if they are within scan range, but this could be faster?

Dunno, what was your first idea ?

Well in my first post, I haven't explained how to solve your probleme but a way to draw a 3D sphere scanner... I think you already know how to do that.

About rendering the sphere as a hud object, there's a common way to do it : use billboarding, so as the sphere will be in the 3D scene, but its location on screen will alwais be the same (facing the camera or wherever you want)...

Here's a link for a pretty nice billboarding tutorial : http://www.lighthouse3d.com/opengl/billboarding/index.php3?billInt

Hope it'll help...

Chman
Offline Middy

Junior Devvie




Java games rock!


« Reply #8 - Posted 2004-11-09 06:32:14 »

K I was under the impresion that billboarding was based on how on objects faces a camera.


Talked to a guy yesterday who suggested that I'd use a combination of ortho projection and prespective projection.

Ortho to bring the sphere into my screen coordinates and glu.perspective will render it using a perspective projection. (it looks weird though so I am doing something wrong)

Another method would be to render the damn sphere before I rotate  my scene, eg do GLU.lookat. That way the sphere wont be rotated in anyway.



When do I get my makeMyGameAsILike() extension?
Offline Middy

Junior Devvie




Java games rock!


« Reply #9 - Posted 2004-11-09 19:32:59 »

I made it work

The solution is simple, make sure your HUD is drawn as the last object.

Clear the z buffer using GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);


Use GLU.perspective

draw whatever you want and it will work :-) WEEEHAA


If anyone is intrested i'll post my code here when its a bit more refined. Grin

- A smal step for mankind huge fall for me

When do I get my makeMyGameAsILike() extension?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Chman

Junior Devvie




Nothing more that... Java games are cool !


« Reply #10 - Posted 2004-11-09 20:26:49 »

Congrats !
It really interests me because I've never succeed in including a 3D object into a 2D HUD...
So if you could post some code it would be very great Smiley !

Chman
Offline Middy

Junior Devvie




Java games rock!


« Reply #11 - Posted 2004-11-11 18:13:36 »

I am still working on code. But I'll post my stuff anyway

Along with a screenshot. The radar is not placed at the camera its placed in origo (0,0,0).




1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
           
                  GL11.glMatrixMode(GL11.GL_PROJECTION);
                  GL11.glPushMatrix();
                  GL11.glLoadIdentity();

                  GLU.gluPerspective(45f,((float)Display.getDisplayMode().getWidth())/Display.getDisplayMode().getHeight(),0.1f,1000f);
           
                  GL11.glMatrixMode(GL11.GL_MODELVIEW);
                  GL11.glPushMatrix();
                  GL11.glLoadIdentity();

     
                       
                  GL11.glPushMatrix();
                 
           
                 
                  GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK,GL11.GL_LINE);
                 
                  GL11.glDisable(GL11.GL_LIGHTING);
                  GL11.glDisable(GL11.GL_TEXTURE_2D) ;        
                  GL11.glEnable(GL11.GL_BLEND);
                  GL11.glEnable(GL11.GL_LINE_SMOOTH);
                  GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                 
                  GL11.glScalef(0.5f,0.5f,0.5f);
                 
                  //green color
                  GL11.glColor4f(0,1,0,0.1f);
                 
                  //Draw scan sphere
                  Sphere s = new Sphere();
                  GL11.glTranslatef(-4.2f,-2.5f,-10); //FIXME:make this hack dependant on screen resolution
                  //rot +=0.1f;
                  GL11.glRotatef(85,1f,0f,0);
                  GL11.glScalef(0.05f,0.05f,0.05f);
                  s.draw(sso.get_scanRange(),10,10);
                 
     
                 
                  //draw scanned objects
                  for(PositionRotation pr : sso._scannedObjects){
                        GL11.glTranslatef(pr.get_position()._x ,pr.get_position()._y ,pr.get_position()._z);
                        GL11.glColor4f(1,0,0,1);
                        GL11.glPointSize(3);
                        GL11.glBegin(GL11.GL_POINTS);
                        GL11.glVertex3f(0,0,0);
                        GL11.glEnd();
                       
                                   
                  }
                 
                  GL11.glEnable(GL11.GL_TEXTURE_2D);
                  GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
                  GL11.glEnable(GL11.GL_LIGHTING);
           
                  GL11.glColor4f(1,1,1,1);
                       
            GL11.glPopMatrix();
           
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glPopMatrix();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glPopMatrix();

When do I get my makeMyGameAsILike() extension?
Offline Chman

Junior Devvie




Nothing more that... Java games are cool !


« Reply #12 - Posted 2004-11-11 20:13:26 »

Many thanks for your code !
And the screenshot looks very promising Wink

Chman
Pages: [1]
  ignore  |  Print  
 
 

 
DesertCoockie (52 views)
2018-05-13 18:23:11

nelsongames (82 views)
2018-04-24 18:15:36

nelsongames (74 views)
2018-04-24 18:14:32

ivj94 (757 views)
2018-03-24 14:47:39

ivj94 (87 views)
2018-03-24 14:46:31

ivj94 (643 views)
2018-03-24 14:43:53

Solater (102 views)
2018-03-17 05:04:08

nelsongames (184 views)
2018-03-05 17:56:34

Gornova (426 views)
2018-03-02 22:15:33

buddyBro (1086 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!