public static EulerRotation operator +(EulerRotation rot1, EulerRotation rot2) { if (rot1 == null) { if (rot2 == null) { return(null); } else { return(rot2); } } if (rot2 == null) { return(rot1); } EulerRotation newRotation = new EulerRotation(0.0, 0.0, 0.0); newRotation.X = ((rot1.X + rot2.X) % 360); newRotation.Y = ((rot1.Y + rot2.Y) % 360); newRotation.Z = ((rot1.Z + rot2.Z) % 360); return(newRotation); }
public static EulerRotation operator -(EulerRotation rot1, EulerRotation rot2) { EulerRotation newRotation = new EulerRotation(0.0, 0.0, 0.0); newRotation.X = Math.Abs(rot1.X - rot2.X); newRotation.Y = Math.Abs(rot1.Y - rot2.Y); newRotation.Z = Math.Abs(rot1.Z - rot2.Z); return(newRotation); }
public GtkGL.EulerRotation ToEulerRotation() { GtkGL.EulerRotation eRot; double angle_x, angle_y, angle_z; double C, RADIANS = 57.2999999999999; double trX, trY; // Calculate Y-axis angle angle_y = Math.Asin(matrix[2]); C = Math.Cos(angle_y); angle_y *= RADIANS; // Throw an exception if we have encountered Gimbal Lock if (Math.Abs(C) <= 0.005) { throw new GtkGL.EulerRotation.GimbalLock(); } trX = matrix[10] / C; trY = -matrix[6] / C; angle_x = Math.Atan2(trY, trX) * RADIANS; trX = matrix[0] / C; trY = -matrix[1] / C; // Get Z-axis angle angle_z = Math.Atan2(trY, trX) * RADIANS; // return only positive angles in [0,360] if (angle_x < 0) { angle_x += 360.0; } if (angle_y < 0) { angle_y += 360.0; } if (angle_z < 0) { angle_z += 360.0; } eRot = new EulerRotation(); eRot.X = angle_x; eRot.Y = angle_y; eRot.Z = angle_z; return(eRot); }
private void Init(GtkGL.IGLObject glObject, GtkGL.EulerRotation rot) { this.eRot = rot; this.glObject = glObject; if(pressedConnected == false){ this.Pressed += OnPressed; pressedConnected = true; } if(releasedConnected == false){ this.Released += OnReleased; releasedConnected = true; } }
public static EulerRotation RotMatrixToEuler(float[] mat) { float angle_x, angle_y, angle_z; float C, RADIANS = 57.2999999999999f; float trX, trY; if(mat == null) throw new System.ArgumentNullException(); if(mat.Length != 16) throw new System.ArgumentException(); angle_y = (float) Math.Asin( mat[2]); /* Calculate Y-axis angle */ C = (float) Math.Cos( angle_y ); angle_y *= RADIANS; if ( Math.Abs( C ) > 0.005 ) /* Gimball lock? */ { trX = mat[10] / C; /* No, so get X-axis angle */ trY = -mat[6] / C; angle_x = (float) Math.Atan2( trY, trX ) * RADIANS; trX = mat[0] / C; /* Get Z-axis angle */ trY = -mat[1] / C; angle_z = (float) Math.Atan2( trY, trX ) * RADIANS; } else { /* Gimball lock has occurred */ angle_x = 0; /* Set X-axis angle to zero */ trX = mat[5]; /* And calculate Z-axis angle */ trY = mat[4]; angle_z = (float) Math.Atan2( trY, trX ) * RADIANS; } /* return only positive angles in [0,360] */ if (angle_x < 0) angle_x += 360.0f; if (angle_y < 0) angle_y += 360.0f; if (angle_z < 0) angle_z += 360.0f; EulerRotation eRot = new EulerRotation(); eRot.X = angle_x; eRot.Y = angle_y; eRot.Z = angle_z; return eRot; }
public static EulerRotation operator +(EulerRotation rot1, EulerRotation rot2) { if(rot1 == null) if(rot2 == null) return null; else return rot2; if(rot2 == null) return rot1; EulerRotation newRotation = new EulerRotation(0.0, 0.0, 0.0); newRotation.X = ( (rot1.X + rot2.X) % 360 ); newRotation.Y = ( (rot1.Y + rot2.Y) % 360 ); newRotation.Z = ( (rot1.Z + rot2.Z) % 360 ); return newRotation; }
public static EulerRotation operator -(EulerRotation rot1, EulerRotation rot2) { EulerRotation newRotation = new EulerRotation(0.0, 0.0, 0.0); newRotation.X = Math.Abs( rot1.X - rot2.X ); newRotation.Y = Math.Abs( rot1.Y - rot2.Y ); newRotation.Z = Math.Abs( rot1.Z - rot2.Z ); return newRotation; }
public void Rotate(GtkGL.EulerRotation er) { Rotate(er.ToQuaternion()); }
public GtkGL.EulerRotation ToEulerRotation() { GtkGL.EulerRotation eRot; double angle_x, angle_y, angle_z; double C, RADIANS = 57.2999999999999; double trX, trY; // Calculate Y-axis angle angle_y = Math.Asin( matrix[2]); C = Math.Cos( angle_y ); angle_y *= RADIANS; // Throw an exception if we have encountered Gimbal Lock if ( Math.Abs( C ) <= 0.005 ) throw new GtkGL.EulerRotation.GimbalLock(); trX = matrix[10] / C; trY = -matrix[6] / C; angle_x = Math.Atan2( trY, trX ) * RADIANS; trX = matrix[0] / C; trY = -matrix[1] / C; // Get Z-axis angle angle_z = Math.Atan2( trY, trX ) * RADIANS; // return only positive angles in [0,360] if (angle_x < 0) angle_x += 360.0; if (angle_y < 0) angle_y += 360.0; if (angle_z < 0) angle_z += 360.0; eRot = new EulerRotation(); eRot.X = angle_x; eRot.Y = angle_y; eRot.Z = angle_z; return eRot; }
/* // This handler is attached to ObjectRotationButton's Rotated event. // Every time the button modifies the object's rotation, the Rotated event fires. // When the object's rotation is modified, we modify our copy of the object's rotation. // TODO: I personally think that we should get the rotation data from the object directly, // but this proves to be difficult, as I don't know how to convert from a rotation matrix // to Euler angles without causing gimbal lock. This will likely be changed when I find // a work-around. */ private void UpdateRotationValues(object o, EventArgs e) { eRot = glOb.GetEulerRotation(); UpdateEntryFields(); }
/* // This handler is attached to the entry fields' Activated event // When the user enters a new value and presses enter, this handler fires. // TODO: I also need to attach the "tabbed out of" event to this method and do some // final checks to make sure the current value is not the same as what "tabbed out of" */ private void UpdateObjectRotation(object o, EventArgs e) { // Clear the rotation state, don't fire the Update handlers glOb.ResetRotation(false); // Rotate the object based on our Euler angles // Grab the current rotation from the object eRot = glOb.GetEulerRotation(); // Get the new values from the entry fields float newX = Convert.ToSingle(((Gtk.Entry)entryMap['x']).Text.ToString()); float newY = Convert.ToSingle(((Gtk.Entry)entryMap['y']).Text.ToString()); float newZ = Convert.ToSingle(((Gtk.Entry)entryMap['z']).Text.ToString()); // Create a new rotation from these values GtkGL.EulerRotation newRot = new GtkGL.EulerRotation(newX,newY,newZ); // Find the difference between the two GtkGL.EulerRotation diffRot = eRot - newRot; // If the rotation has changed, create a quaternion from the Euler rotation // and apply it to the object if(diffRot != GtkGL.EulerRotation.Identity) glOb.Rotate(diffRot); }
// This method updates the values stored in the X, Y and Z entry fields from the object's rotation // It is used more than once, so it gets its own handle :) public void UpdateEntryFields() { // Grab the current rotation eRot = glOb.GetEulerRotation(); // Normalize negative values before displaying eRot.X = (eRot.X + 360) % 360; eRot.Y = (eRot.Y + 360) % 360; eRot.Z = (eRot.Z + 360) % 360; ((Gtk.Entry) entryMap['x']).Text = eRot.X.ToString(); ((Gtk.Entry) entryMap['y']).Text = eRot.Y.ToString(); ((Gtk.Entry) entryMap['z']).Text = eRot.Z.ToString(); }