How to solve the gimbal lock in .NET?

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
SpacePowo
Posts: 8
Joined: Fri Jul 15, 2005 2:37 am
Contact:

How to solve the gimbal lock in .NET?

Post by SpacePowo »

Does Irrlicht happen to have any type of feature where you can do some free degrees of rotation as in pitch, yaw and rolling??

Or do we have to do some calculations itself?

I know how the C++ thing can be done but what about C#.NET?
Aire
Posts: 9
Joined: Tue Mar 15, 2005 3:44 pm

Post by Aire »

I am unsure how Irrlicht approaches rotations at the moment, I am guessing using matrices. I myself prefer quaternions because they all together avoid the gimbal lock. But, I am not quite sure what you are looking for here. Are you looking for a way to use Euler (yaw/pitch/roll) Angles and translate them to the native Irrlicht rotation methods?
SpacePowo
Posts: 8
Joined: Fri Jul 15, 2005 2:37 am
Contact:

Post by SpacePowo »

Anything that gets me out of a gimbal lock..

Yeah Pitch, Yaw and Roll.
SpacePowo
Posts: 8
Joined: Fri Jul 15, 2005 2:37 am
Contact:

Post by SpacePowo »

I've tried this method in ittlicht using VB.NET instead:

'Yaw
X = zpos(i) * Sin(Yaw) + xpos(i) * Cos(Yaw)
Y = ypos(i)
z = zpos(i) * Cos(Yaw) - xpos(i) * Sin(Yaw)

'Pitch
X2 = X
y2 = Y * Cos(Pitch) - z * Sin(Pitch)
Z2 = Y * Sin(Pitch) + z * Cos(Pitch)

'Roll
x3 = y2 * Sin(Roll) + X2 * Cos(Roll)
Y3 = y2 * Cos(Roll) - X2 * Sin(Roll)
z3 = Z2

And the rotation didn't go well.

If someone can provide an example either in VB.NET or C#.NET, then I would be happy camper. I'm too lazy to do it right myself since it's late at night.

Though there seems to be a lack of examples provided with the .NET framework.
SpacePowo
Posts: 8
Joined: Fri Jul 15, 2005 2:37 am
Contact:

Post by SpacePowo »

I've tried this method in ittlicht using VB.NET instead:

'Yaw
X = zpos(i) * Sin(Yaw) + xpos(i) * Cos(Yaw)
Y = ypos(i)
z = zpos(i) * Cos(Yaw) - xpos(i) * Sin(Yaw)

'Pitch
X2 = X
y2 = Y * Cos(Pitch) - z * Sin(Pitch)
Z2 = Y * Sin(Pitch) + z * Cos(Pitch)

'Roll
x3 = y2 * Sin(Roll) + X2 * Cos(Roll)
Y3 = y2 * Cos(Roll) - X2 * Sin(Roll)
z3 = Z2

And the rotation didn't go well.

If someone can provide an example either in VB.NET or C#.NET, then I would be happy camper. I'm too lazy to do it right myself since it's late at night.

Though there seems to be a lack of examples provided with the .NET framework.

Edit: I noticed the previous code it used for making 3D drawings on a 2D screen.
Sergio Cossa
Posts: 22
Joined: Fri Jun 03, 2005 2:00 pm
Location: Argentina

Post by Sergio Cossa »

Hi!

I don't still know a lot of develop in games 3D and Irrlicht, but I am making some tests with code that appears in this post:

http://irrlicht.sourceforge.net/phpBB2/ ... ra&start=0

There are some samples in c++ and an adaptation that made for C#. It is not complete, but with something of effort one can make run.

Some day the community. NET of Irrlicht will have thousands of examples to advance more quickly :D
Sergio Cossa
Argentina
SpacePowo
Posts: 8
Joined: Fri Jul 15, 2005 2:37 am
Contact:

Post by SpacePowo »

I am having a hard time converting this to VB.NET.

I am taking one segment at a time and putting it in to the VB code.
In C#

Code: Select all

//--- rotate node relative to its current rotation -used in turn,pitch,roll ---
      public static void Rotate(Irrlicht.Scene.ISceneNode node, Irrlicht.Core.Vector3D rot) {
         Irrlicht.Core.Matrix4 m = node.RelativeTransformation;
         Irrlicht.Core.Matrix4 n = new Irrlicht.Core.Matrix4();
         n.SetRotationDegrees(rot);
         m *= n;
         node.Rotation = getRotationDegrees( m );
      } 
TO VB.NET

Code: Select all

Public Sub Rotate(ByVal node As Irrlicht.Scene.ISceneNode, ByVal rot As Irrlicht.Core.Vector3D)
 Dim m As Irrlicht.Core.Matrix4 = node.RelativeTransformation
 Dim n As Irrlicht.Core.Matrix4 = New Irrlicht.Core.Matrix4
 n.SetRotationDegrees(rot)
 m *= n
 node.Rotation = getRotationDegrees(m)
End Sub
So is there any where how I can convert where A *= B to VB.NET?

I suppose A=A*B?

Sorry I know a little about C#.
Irme
Posts: 55
Joined: Sat Jul 16, 2005 8:24 am

Post by Irme »

you should be able to use *= in vb.net if not yes you would do a = a*b
SpacePowo
Posts: 8
Joined: Fri Jul 15, 2005 2:37 am
Contact:

Post by SpacePowo »

Ok I think I got a compiler error.

C:\Documents and Settings\xxxxxxxxx\My Documents\SharpDevelop Projects\blank\MainClass.vb(222) : error BC30452: Operator '*' is not defined for types 'Irrlicht.Core.Matrix4' and 'Irrlicht.Core.Matrix4'.

m=m*n

Though previously that m*=n in the c# code.
Irme
Posts: 55
Joined: Sat Jul 16, 2005 8:24 am

Post by Irme »

you may want to see if the matrix4 class has a multiply function built in - if not you will have to multiply each aspect of the matrix4 individualy like this

mat1.x = mat1.x * mat2.x
mat1.y = mat1.y * mat2.y
Locked