Results 1 to 7 of 7

Thread: Having quads always face the camera

  1. #1
    Member Contributor
    Join Date
    Nov 2002
    Posts
    96

    Having quads always face the camera

    At the moment I'm working on a neat little particle engine. I only have one little problem: the Quads don't alwas face the camera.

    For example, when I start the engine the quads nicely face the camera with their entire surface, but when I move around the engine they become thinner, and thinner, up untill they are no more than a thin line (or invisible).

    How would I make the quads face the camera no matter the rotation? Any example code is welcome.

    Thank you!

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    Florence, Ky USA
    Posts
    27

    Re: Having quads always face the camera

    assuming you know your camera's rotation.. all you have to do is do a negative rotation for the particles... (this makes them face the camera if it were a vector, not really right to the camera... but for most gaming purposes you can't tell the difference)

    Kent

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: Having quads always face the camera

    You should look for billboarding tutorials, although they work best with vertexshaders

  4. #4
    Member Contributor
    Join Date
    Nov 2002
    Posts
    96

    Re: Having quads always face the camera

    Originally posted by Kent767:
    assuming you know your camera's rotation.. all you have to do is do a negative rotation for the particles... (this makes them face the camera if it were a vector, not really right to the camera... but for most gaming purposes you can't tell the difference)

    Kent

    OK, How would I do this? I don't know my cams rotation since I use GLULOOKAT.
    I know how I can get the current view matrix (glGetFloatv(GL_MODELVIEW_MATRIX, array)) but which values in that matrix are the rotation (or how would I get them)?


    MadMan, I read something about billboarding in the gamedev book, but it seems to lack a decent snippet (or anything that I can understand)


    [This message has been edited by Structural (edited 12-02-2002).]

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    Florence, Ky USA
    Posts
    27

    Re: Having quads always face the camera

    gluLookAt is kinda limiting, but i've been able to fudge results, (causes some wierd z axis rotations.. i think its something w/ how gluLookAt works, but for most particles that shouldn't matter toooo much, as long as it faces the camera,
    im just cutting code right out of an engine i wrote trying to do it this way...


    Code :
     void GFX::SetCamera(GLfloat ox, GLfloat oy, GLfloat oz, GLfloat tx,GLfloat ty, GLfloat tz)
    {
    	 GLfloat OrientedX, OrientedY,OrientedZ;
    	 if ((oz==0))
    		 oz=0.000000001f;
    	 camXpos=ox;camYpos=oy;camZpos=oz;
    	 OrientedX=tx-ox;
    	 OrientedY=ty-oy;
    	 OrientedZ=tz-oz;
    	 camXrot=0;camYrot=0;
    	 camXrot=(atan(OrientedY/OrientedZ))*180/3.14159;
    	 camYrot=-(atan(OrientedX/OrientedZ))*180/3.14159;
    	 gluLookAt(ox,oy,oz,tx,ty,tz,0,1,0);
    }
    basically its inverse trig stuff... whenever you render the particles just do the rotation in reverse

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    Florence, Ky USA
    Posts
    27

    Re: Having quads always face the camera

    oh had wierd issues with crossing the x axis w/ the camera did a quick fix in the particle routine... so basically this is a very innefective way of doing it, but you can make it work.... its probably better to just write your own camera class to do the matrix rotations...
    Kent

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Having quads always face the camera

    Hum....giving that you are suppling gluLookAt with the points in which to look at.
    With a little vector math you should be able to get the camera rotation.

    Using the first two points in the gluLookAt, you should be able to come up with angle of rotation.

    the other option would be to not use gluLookAt, since it is equal to doing something like the following:

    glTranslatef(x2,y2,z2); // look at
    glRotate( angle_x, 1.0, 0.0, 0.0);
    glRotate( angle_y, 0.0, 1.0, 0.0);
    glRotate( angle_z, 0.0, 0.0, 1.0);
    glTranslatef(x1,y1,z1); // eye point
    // Note bound to be a error here, doing it all in my head.. but it should give you an idea.

    This way you know the angles of rotation supplied vs. maybe having to convert the gluLookAt points to angles.
    Or if you want to keep using glLookAt, it maybe easier to conver angles to the points needed in the gluLookAt, I did a post on this some time back using sin/cos to give rotated points for gluLookAt. I don't have my notes handy on it.


    Originally posted by Structural:

    OK, How would I do this? I don't know my cams rotation since I use GLULOOKAT.
    I know how I can get the current view matrix (glGetFloatv(GL_MODELVIEW_MATRIX, array)) but which values in that matrix are the rotation (or how would I get them)?


    MadMan, I read something about billboarding in the gamedev book, but it seems to lack a decent snippet (or anything that I can understand)


    [This message has been edited by Structural (edited 12-02-2002).]


    [This message has been edited by nexusone (edited 12-02-2002).]

Similar Threads

  1. rotating faces to face the camera?
    By bsabiston in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-07-2013, 11:24 AM
  2. changing back face to front face in vertex shader
    By hoschie211 in forum OpenGL: GLSL
    Replies: 1
    Last Post: 11-03-2009, 12:36 AM
  3. opengl gml per face normal and per face vertex question
    By GaMEFRo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-06-2006, 10:49 AM
  4. Tri's vs. Quads
    By OpenGLRox in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 02-18-2002, 09:55 AM
  5. Rotating a poly to face camera using dot product?
    By JMaynard in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 06-12-2000, 12:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean