Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
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  
  Billboarding, almost there but not quite!  (Read 1681 times)
0 Members and 1 Guest are viewing this topic.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Posted 2005-08-08 14:41:37 »

i've been trying for a while to get billboarding to work with lwjgl, i have been stuck trying to get the code below to work, especially with the vectors, with the code below i'm almost there but a bit stuck with it, i have tried to use the vector class that comes with lwjgl but probably doing it wrong, i've attached the code below any help would be appreciated

thx


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  
import org.lwjgl.opengl.GL11;
import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.util.vector.Vector3f;
...

public void draw(int x, int y, int z) {

// setup variables
Vector3f center = null; // this will be the center point of the quad
Vector3f right = null, up = null; // used to hold the x-right and y-up vectors
Vector3f a, b, c, d; // four corners of the quad

     
// set location of quad
GL11.glTranslatef(x, y, z);

GL11.glPushMatrix();

   FloatBuffer buf = BufferUtils.createFloatBuffer(16 * 4);

   // Get your current model view matrix from OpenGL.
   GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, buf);

   // rewind the buffer
        buf.rewind();


   // build vectors from model matrix
   right.set(buf.get(0), buf.get(4), buf.get(8));
   up.set(buf.get(1), buf.get(5), buf.get(9));


   // setup center variable, this is center point of the quad
   center.set(buf.get(12), buf.get(13), buf.get(14));


   // setup corners of quad to face camera
   a = center - (right + up) * size;
   b = center + (right - up) * size;
   c = center + (right + up) * size;
   d = center - (right - up) * size;


   // bind the texture of image to be displayed on quad
   texture.bind();

        GL11.glBegin(GL11.GL_QUADS);                     // Build Quad
       
            GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3fv(a); // Bottom Left
            GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3fv(b); // Bottom Right
            GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3fv(c); // Top Right
            GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3fv(d); // Top Left 
           
        GL11.glEnd();                                                  // Done Building Quad               
                             
GL11.glPopMatrix();
}
Offline anarchotron

Junior Duke




...precious bodily fluids.


« Reply #1 - Posted 2005-08-08 14:57:46 »

The translation portion of the matrix is stored in 3,0 3,1 3,2, like:

| 1 0 0 X |
| 0 1 0 Y |
| 0 0 1 Z |
| 0 0 0 1 |

That means the index 12, 13, 14 elements of your 16 float buffer.

so

center.set(buf.get(12), buf.get(13), buf.get(14));
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Reply #2 - Posted 2005-08-08 15:02:23 »

thx for ur reply, but the thing is what is "center.set" is it an array or something and how is the calculation done to store there?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline anarchotron

Junior Duke




...precious bodily fluids.


« Reply #3 - Posted 2005-08-08 15:05:49 »

Oh I assumed center was a Vector3f.  I now see you declared it as a float....  I intended it as a vector.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Reply #4 - Posted 2005-08-08 15:07:51 »

ok thx for the update, if made the changes but i don't think the Vector3f, class works as it should any idea?
Offline anarchotron

Junior Duke




...precious bodily fluids.


« Reply #5 - Posted 2005-08-08 15:15:44 »

Well I use Vector3f all the time with no problems.  What isn't working as it should?  I notice you have some code in there:

 // setup corners of quad to face camera
a = center - (right + up) * size;
b = center + (right - up) * size;
c = center + (right + up) * size;
d = center - (right - up) * size;

That looks like c++, Vector3f doesn't support those operators.



Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Reply #6 - Posted 2005-08-08 15:22:04 »

ah i see, those bits are the problem:


// setup corners of quad to face camera
a = center - (right + up) * size;
b = center + (right - up) * size;
c = center + (right + up) * size;
d = center - (right - up) * size;

and

GL11.glVertex3fv(a); // Bottom Left
GL11.glVertex3fv(b); // Bottom Right
GL11.glVertex3fv(c); // Top Right
GL11.glVertex3fv(d); // Top Left

i was using a c++ tutorial to get it working, so how would you do the same thing with lwjgl, or is there a different way?

thx
Offline anarchotron

Junior Duke




...precious bodily fluids.


« Reply #7 - Posted 2005-08-08 15:36:45 »

Unfortunately these operations are somewhat cumbersome with the Vector3f.  Here's one suggestion:


a = center - (right + up) * size;
b = center + (right - up) * size;
c = center + (right + up) * size;
d = center - (right - up) * size;



a.set(center.x - (right.x + up.x) * size, center.y - (right.y + up.y) * size,  center.z - (right.z + up.z) * size);

etc...

Or with a temporary:

JwVector3f tmp = new JwVector3f();
Vector3f.sub(center, (Vector3f)Vector3f.add(right, up, tmp).scale(size),  a);


It's unfortunate that Vector3f.scale() returns as a Vector rather than Vector3f.

You should be able get away with using your result vector as your temporary, but I didn't research it to make sure:

Vector3f.sub(center, (Vector3f)Vector3f.add(right, up, a).scale(size),  a);


You could also possibly save some time by precomputing stuff, at the expense of a little more storage.  (You'd want to pre-allocate if you are doing this alot)



Vector3f rightPlusUp = (Vector3f)Vector3f.add(right, up, new Vector3f()).scale(size);
Vector3f rightMinusUp = (Vector3f)Vector3f.sub(right, up, new Vector3f()).scale(size);

Vector3f.sub(center, rightPlusUp, a);
Vector3f.add(center, rightMinusUp, b);
Vector3f.add(center, rightPlusUp, c);
Vector3f.sub(center, rightMinusUp, d);



Hope this rambling helps!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (36 views)
2014-10-27 03:28:38

TehJavaDev (29 views)
2014-10-27 03:27:51

DarkCart (42 views)
2014-10-26 19:37:11

Luminem (23 views)
2014-10-26 10:17:50

Luminem (28 views)
2014-10-26 10:14:04

theagentd (34 views)
2014-10-25 15:46:29

Longarmx (62 views)
2014-10-17 03:59:02

Norakomi (60 views)
2014-10-16 15:22:06

Norakomi (49 views)
2014-10-16 15:20:20

lcass (44 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!