-1

Is it possible to rotate a game Object by applying the Rotation matrix to it. Instead of passing each angle and rotating it.

I tried to use GL.MultMatrix() but there is no movement in game Object

Code sinppet:

    GL.PushMatrix();
    GL.MultMatrix(m);
    GL.PopMatrix(); 

The above snippet is in update() function. Docs says GL.MultMatrix() is similar to glMultMatrix in opengl library.Which we can use in openGl to Rotate right!!

If there is any method to achieve this please mention. Thanks

djkpA
  • 1,224
  • 2
  • 27
  • 57
  • From the doc "GL drawing commands execute immediately. That means if you call them in Update(), they will be executed before the camera is rendered (and the camera will most likely clear the screen, making the GL drawing not visible)." Did you try to put that in OnPostRender() ? – Roknus Apr 08 '16 at 07:49
  • I am not drawing anything on scene , just trying to rotate a game Object and I attached this script to game Object .I tried OnPostRender() also didn't work – djkpA Apr 08 '16 at 07:54
  • I don't think you can do that this way then because here you are just pushing a matrix not assigning it to the gameObject and AFAIK there is no function that allow that with GL. – Roknus Apr 08 '16 at 08:05
  • Is there any way to assign it to game Object and achieve it – djkpA Apr 08 '16 at 08:08
  • I thing that ` GL.PopMatrix()` restores the computed value – djkpA Apr 08 '16 at 08:24

1 Answers1

0

I'm not sure what you are trying to achieve but using GL for rotation probably is not a good idea. Have you had a look at Matrix4x4?

I don't know matrices well but I can tell you GL works with slightly different logic. You need to manually draw your stuff between the MultMatrix() and PopMatrix() commands using GL class (like GL.Vertex3) which gives you absolute control of how things are rendered but is redundant as hell.

Nika Kasradze
  • 2,834
  • 3
  • 25
  • 48
  • I am not drawing anything on scene , just trying to rotate a game Object by giving rotation matrix and I attached this script to that particular game Object – djkpA Apr 08 '16 at 07:55
  • @javvajikiran , I agree with @Nika . Why do not try **Quaternion**, it is simpler and powerful. Just like: `tranform.rotation*=Quaternion.AngleAxis(, transform.right); //or Vector3.right` [Wiki Quaternion](https://en.wikipedia.org/wiki/Quaternion) – tim Apr 08 '16 at 08:49
  • Yeah I can but may I know why the above code is not working – djkpA Apr 08 '16 at 09:13
  • 1
    GL is for drawing new stuff, it will not redraw or somehow modify existing transforms in the game. Between `GL.MultMatrix(m);` and `GL.PopMatrix();` you shell make calls to `GL` drawing methods to draw stuff. Please see the example in the GL class documentation. – Nika Kasradze Apr 08 '16 at 10:46