Author Topic: Individual Mesh Rotation  (Read 21016 times)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Individual Mesh Rotation
« on: June 06, 2018, 02:57:31 pm »
Mike

I have started to work on the individual mesh rotation, using a new meta #rotate rStep, rX, rY, rZ that is based on
glRotatef(rStep, rX, rY, rZ) to perform the rotation
at the end of struct MobjMat, i have added this new parameter
float rotate[4];  // PAT: 06-05-2018 dito glRotatef(rSpeed, rX, rY, rZ);

However in order to perform a correct rotation i need to use
glTranslatef(-x, -y, -z) // Move to center
glRotatef(rotation_angle, 0.0f, 0.0f, axisToUse)
glTranslate(x, y, z) // Restore the initial location

I was thinking to use something similar to what you have done in billboard and calcMeshBounds to retrieve the correct
x, y, z mesh bounds to apply the translation.

Do you think that it is the best way to do it ?

Added:
// Dirty code to test the rotation
if (pMaterial->rotate[0] != 0.0f) {
    userotate += 5.0;
    if (userotate > 360.0f) { userotate = userotate - 360.0f; }
    float rx = 1.0f; if (pMesh->centerPoint[0] > 0.0f) { rx = -1.0f; }
    float ry = 1.0f; if (pMesh->centerPoint[1] > 0.0f) { ry = -1.0f; }
    float rz = 1.0f; if (pMesh->centerPoint[2] > 0.0f) { rz = -1.0f; }
    glTranslatef(pMesh->centerPoint[0] * rx, pMesh->centerPoint[1] * ry, pMesh->centerPoint[2] * rz);
    glRotatef(userotate, 0.0f, 0.0f, 1.0f);
    rx = -rx; ry = -ry; rz = -rz;
    glTranslatef(pMesh->centerPoint[0] * rx, pMesh->centerPoint[1] * ry, pMesh->centerPoint[2] * rz);
}

To see the result look at the attached video
« Last Edit: June 07, 2018, 11:01:48 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Individual Mesh Rotation
« Reply #1 on: June 06, 2018, 09:22:22 pm »


Quote
in order to perform a correct rotation i need to use...

Exactly! The OpenGL primitive glRotate() works for an individual mesh within a model correctly only when this particular mesh's center point is placed at [0,0,0] in the world coordinate system. This is achieved by translating the model to [-meshCenterX, -meshCenterY, -meshCenterZ] (== world center [0,0,0]), performing the desired rotation, and then putting the model back in its original position by translating it to [meshCenterX, meshCenterY, meshCenterZ].

Quote
Do you think that it is the best way to do it ?

This is the only way to do it.

Quote
// Dirty code to test the rotation

Why not simply

    //float rx = pMesh->centerPoint[0] > 0.0f ? 1.0 : -1.0f;
    //float ry = pMesh->centerPoint[1] > 0.0f ? 1.0 : -1.0f;
    //float rz = pMesh->centerPoint[2] > 0.0f ? 1.0 : -1.0f;

    glTranslatef(-pMesh->centerPoint[0], -pMesh->centerPoint[1], -pMesh->centerPoint[2]);
    glRotatef(userotate, 0.0f, 0.0f, 1.0f);
    //rx = -rx; ry = -ry; rz = -rz;
    glTranslatef(pMesh->centerPoint[0], pMesh->centerPoint[1], pMesh->centerPoint[2]);


?
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Individual Mesh Rotation
« Reply #2 on: June 07, 2018, 08:51:25 am »
Quote
Why not simply
Of course that was the first thing i played with, but that didn't work well.
(i can send you a WIP if you want to try it in context)

Next step would be to add audio support, to hear the engine, with the volume matching the zooming factor  ;D
« Last Edit: June 07, 2018, 08:59:17 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Individual Mesh Rotation
« Reply #3 on: June 07, 2018, 09:37:52 am »
... that didn't work well.

 :o :o :o

Quote
(i can send you a WIP if you want to try it in context)

Yes, please do.

Quote
Next step would be to add audio support, to hear the engine, with the volume matching the zooming factor  ;D



Yes, real time animation is the most exquisite effect in the entire 3D virtuality. :)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Individual Mesh Rotation
« Reply #4 on: June 07, 2018, 11:00:17 am »
Here is another video, showing the Tron engine animated.

The problem is that the mesh must be correctly aligned to match the rotation axis, but the extra work is worth the result.

I shall prepare a WIP + object…
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Individual Mesh Rotation
« Reply #5 on: June 07, 2018, 11:07:01 am »
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Individual Mesh Rotation
« Reply #6 on: June 07, 2018, 01:22:43 pm »
tron_ani.zip (to put into your Tron folder)
prop.zip (to put into your Corsair folder)
mobj.zip (mobj.h search for "Test rotation" into Mobj_DrawUsingFixedFuncPipeline)

How to use it
in the View menu select:
1 - Show FPS counter (for now, you have to check it for the purpose of animation, until full code completion)
2 - Use fixed pipeline (not done yet into Mobj_DrawUsingProgrammablePipeline)

Of course you can use also Y rotation.

Material example:

newmtl propspinn
#rotate 5.0 0.0 0.0 1.0
Ka 0.1 0.1 0.1
Kd 0.75 0.75 0.75
Ks 0.75 0.75 0.75
Ns 10
d 0.25
illum 1
map_Kd prop.png


Airplane sound Library
https://www.freesoundeffects.com/free-sounds/airplane-10004/20/tot_sold/20/2/

Note: to invert the propeller rotation the first speed parameter must be negative.
#rotate -5.0 0.0 0.0 1.0
« Last Edit: June 07, 2018, 01:53:04 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Individual Mesh Rotation
« Reply #7 on: June 07, 2018, 03:51:44 pm »
Thank you Patrice!

I'm expecting my friends to come to my place any minute now so I'll come back with my feedback to you tomorrow. :)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Individual Mesh Rotation
« Reply #8 on: June 07, 2018, 05:34:40 pm »
Of course that was the first thing i played with, but that didn't work well.

Patrice,

It should have worked! :-\ It must be the same glitch (probably in MS VC) I was observing when working out the billboard routine... Both implementations should essentially resolve to the exact same simple sign bit reversal but the simpler code fails.  :o >:(
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Individual Mesh Rotation
« Reply #9 on: June 07, 2018, 07:17:45 pm »
Here is a patch, that performs rotation detection, to fire the animation accordingly.

Search for gP.nRotation.

rotation now works in both PPL and FFP mode.
« Last Edit: June 07, 2018, 07:22:52 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Individual Mesh Rotation
« Reply #10 on: June 08, 2018, 05:16:55 am »
Thank you Patrice, everything seems to be working fine for me.

Still I see it worthwhile to be able to stop all animation completely in order to have a chance to explore the model with all its meshes in complete stasis. On default, the animation effects may be on if available in the mat file but there should also be a checkbox or button to switch them off and inspect the model in its raw state if needed. If it's a checkbox, I think it can fit in logically very well somewhere near the existing model rotation checkbox. A couple of sliders could also be welcome to adjust the rotation and animation speeds in real time. If we sacrifice your magnificent alpha threshold control's rotating knob and segmented display, we would probably be able to squeeze in all the three sliders and the animation checkbox in the right-side panel space thus freed.

Regarding Tron, I think it can be more interesting and spectacular to have the bike bump-mapped tires, rather than the engine insides, rotating when animated. (will have to watch the movie once again though to verify if the original engine had any moving parts...)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Individual Mesh Rotation
« Reply #11 on: June 08, 2018, 06:13:34 am »
Patrice,

I want to know exactly how you cooked up this trick (what was your exact train of thought):

    float rx = pMesh->centerPoint[0] > 0.0f ? -1.0f : 1.0f;
    float ry = pMesh->centerPoint[1] > 0.0f ? -1.0f : 1.0f;
    float rz = pMesh->centerPoint[2] > 0.0f ? -1.0f : 1.0f;
    glTranslatef(pMesh->centerPoint[0] * rx, pMesh->centerPoint[1] * ry, pMesh->centerPoint[2] * rz);
    ........
    rx = -rx; ry = -ry; rz = -rz;
    glTranslatef(pMesh->centerPoint[0] * rx, pMesh->centerPoint[1] * ry, pMesh->centerPoint[2] * rz);


or if the trick wasn't yours, where did you pry it?
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Individual Mesh Rotation
« Reply #12 on: June 08, 2018, 10:31:50 am »
Quote
everything seems to be working fine for me.
I wanted to do it for long ;)

Quote
I want to know exactly how you cooked up this trick
That was a pragmatic decision of my own.
Because negate failed, i took the decision to switch to brute force to let it work the way it should.
Perhaps the problem is because we are using pointers (pMesh->centerpoint), however i am not a C++ expert and i have no idea of the code optimization performed by the compiler.

Quote
Animation On/Off
Of course this is mandatory, and i have to think to the most ergonomic location…

Quote
Tron
I have reworked the rotating mesh engine altogether with a new texture, because the original was not perfectly aligned along the z axis. I am also using a slighty bigger engine

Things are much more complex when the mesh is using an angle along any of the x,y,z.
So far i am only dealing with perfect x,y,z alignments ...
« Last Edit: June 08, 2018, 11:35:48 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Individual Mesh Rotation
« Reply #13 on: June 08, 2018, 07:56:21 pm »
We must compute the exact individual mesh centerpoint, based on the rotation axis being used.
We can't use the centerpoint computed by CalcMeshBounds.

Patrice
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Individual Mesh Rotation
« Reply #14 on: June 08, 2018, 08:54:03 pm »
I have added the new "Mesh animation" check box.
Patrice
(Always working with the latest Windows version available...)