Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Oct 2005
Offline Last Active Feb 07 2016 03:09 PM

Posts I've Made

In Topic: Problem with Lazy Foo Game Programming Tutorial

07 February 2016 - 01:27 PM

I'm not a Windows expert, but I think the problem is the usage of the main(…) function. That is *nix style, but in Windows you have to use the WinMain(…) or wWinMain(…) function instead. Since you do not do so, your main(…) and a main(…) within a commonly linked object file do collide.

In Topic: Order of transformation confuse

30 January 2016 - 03:36 AM

The matrix product is associative. That means you can put (decently) pairs of parentheses around the individual term at your desire. Now, when you choose parentheses so that you start with the product including the vector, e.g. like so for column vectors (i.e. the vector is on the right and the matrix on the left, typical for OpenGL)

    M1 * M2 * ( M3 * v )

and continue to the outer terms, like so

   = M1 * ( M2 * ( M3 * v ) )

then the parentheses tell you about the locality of the transformation. The wording for this is often "first apply M3, then M2, and then M1", although that wording is imprecise.
Notice that this works for row vectors as well
   ( ( v' * M3' ) * M2' )* M1'
So, if you want to apply scaling to the model, rotate the scaled model, and translate the rotated/scaled model,** and you use column vectors, then the formula with parentheses looks like
    T * ( R * ( S * v ) )
what, obviously, corresponds to your 2nd variant of code.
**Notice please that I've chosen a wording here that is not as blurry as "first … then …" ;)

Opengl reads in reverse order ...

As said above, "order" without further context is misleading here. For example, you can calculate

    ( ( M1 * M2 ) * M3 ) * v

as well and get the same result.

In Topic: Z rotates with X and Y (quaternion rotation)

24 January 2016 - 07:59 AM

I am trying to rotate an object in my game by using quaternions to avoid gimbal lock.

Gimbal lock is the loss of one degree of freedom. Using quaternions does not protect you from gimbal lock.


Wouldn't the new X axis just be the local x axis of my object?

See it this way: Whenever a transformation is done it is done w.r.t. the global space. Ignoring identity transforms, due to transformation a new local space is created.


Let's use 2 rotation as an example. A vector v is transformed:

    v' := R2 * R1 * v = ( R2 * R1 ) * vR2 * ( R1 * v )

Please notice that matrix multiplication is an associative operation, hence using parentheses as above is allowed. Although the 2nd form is what we use in practice due to efficiency reasons, the 3rd form is IMO best suited to think of what happens. It tells us that v is transformed by R1, and the rotated result is transformed by R2.


Now, if you want to use not the global but the local axes when applying R2, you need to first transform R1 * v into a space that is consistent with the global space. Then, after application of R2, rotate it back into the former local space. I.e. wrap R2 accordingly like so:

    v'' := ( R1 * R2 * R1-1) * ( R1 * v )

Notice again that parentheses are pure cosmetic stuff here. They have no mathematical effect. Hence we can rewrite the above stuff as

        R1 * R2 * ( R1-1 * R1 ) * v

and find that the inner term is the identity matrix, hence
        R1 * R2 * v
So here we've shown that the desire to use the local axes for rotation is fulfilled by reversing the order of rotations! For incremental rotations perhaps the 1st form of computing v'' may be better suited.

In Topic: Weird vertical camera rotation

03 January 2016 - 01:07 PM

You seem to map the mouse pointer position to a kind of inclination and azimuth pair of angles, using them together with a fix distance (radius) as spherical coordinates, convert that into cartesian coordinates, and transform that from object local into global space.


Accordingly to the formulas found e.g. at the end of the section here, your trigonometry isn't correct then.

In Topic: Render queues - why are they needed?

03 January 2016 - 10:22 AM

You mean if I sort opaque objects, I can then render these objects safely without glEnable(GL_DEPTH_TEST) ?

If you sort them by depth (in camera space), then yes, assuming that there are no intersections. However, opaque objects are usually sorted by their shader programs, textures, etc., because switching them forth and back is expensive.