internal void render(vec3 p, quat rot) { using (PushedMatrix dnum = new PushedMatrix()) { mat.apply(); Gl.glTranslatef(p.x, p.y, p.z); AxisAngle aa = rot.AxisAngle; // apply rotation Gl.glRotatef(aa.angle.inDegrees, aa.axis.x, aa.axis.y, aa.axis.z); Gl.glBegin(Gl.GL_TRIANGLES); foreach (MeshDef.Vertex[] face in faces) { for (int i = 0; i < 3; ++i) { MeshDef.Vertex v = face[i]; vec3 vert = (poseable.CurrentPose != null) ? poseable.CurrentPose.transforms[v.bone] * v.vertex : v.vertex; Gl.glNormal3f(v.normal.x, v.normal.y, v.normal.z); Gl.glTexCoord2f(v.uv.x, v.uv.y); Gl.glVertex3f(vert.x, vert.y, vert.z); } } Gl.glEnd(); } }
internal void sendRotation() { // -rotatation AxisAngle aa = rotation.AxisAngle; Gl.glRotatef(-aa.angle.inDegrees, aa.axis.x, aa.axis.y, aa.axis.z); }
public static quat FpsQuat(quat rotation, float dx, float dy) { quat rx = new quat(AxisAngle.RightHandAround(vec3.Up, angle.FromDegrees(-dx))); quat ry = new quat(AxisAngle.RightHandAround(rotation.Right, angle.FromDegrees(-dy))); quat final = rx * ry; return(final); }
public quat(AxisAngle aa) { angle half = aa.angle * 0.5f; vec = aa.axis * half.Sin; w = half.Cos; normalize(); }
public quat rotation(vec2 from, vec2 to) { vec3 f = transform(from); vec3 t = transform(to); vec3 axis = vec3.cross(f, t).Normalized; angle angle = vec3.AngleBetween(f, t); return(new quat(AxisAngle.RightHandAround(axis, angle))); }
public static mat44 FromAxisAngle(AxisAngle aa) { float c = aa.angle.Cos; float s = aa.angle.Sin; float x = aa.axis.x; float y = aa.axis.y; float z = aa.axis.z; return(new mat44(new float[] { x *x *(1 - c) + c, x * y * (1 - c) - z * s, x * z * (1 - c) + y * s, 0, y * x * (1 - c) + z * s, y * y * (1 - c) + c, y * z * (1 - c) - x * s, 0, x * z * (1 - c) - y * s, y * z * (1 - c) + x * s, z * z * (1 - c) + c, 0, 0, 0, 0, 1 })); }
public MatrixHelper Rotate(AxisAngle aa) { return(mult(mat44.FromAxisAngle(aa))); }