public InstanceBone(Bone bone) { Bone = bone; Position = bone.Position; RotationMatrix = bone.RotationMatrix; Childeren = new List<InstanceBone>(); }
public InstanceModel(Model model) { Model = model; PlaySpeed = 1; CurrentFrame = model.FrameStart; // orientation Position = Vector3.Zero; Scale = Vector3.One; Rotation = Matrix3.Identity; // objects Objects = new InstanceObject[model.Objects.Length]; for (int i = 0; i != Objects.Length; ++i) { var type = model.Objects[i].GetType(); if (type == typeof(ObjectMesh)) Objects[i] = new InstanceObjectMesh((ObjectMesh)model.Objects[i]); else if (type == typeof(ObjectArmature)) Objects[i] = new InstanceObjectArmature((ObjectArmature)model.Objects[i]); else Debug.ThrowError("InstanceModel", "Unsuported Object type: " + type); } for (int i = 0; i != Objects.Length; ++i) { Objects[i].bindObjects(model.Objects[i]); } }
public static void InersectPlane(ref Line3 line, ref Vector3 planeNormal, ref Vector3 planeLocation, out Vector3 result) { float dot = (-(planeNormal.X*planeLocation.X) - (planeNormal.Y*planeLocation.Y) - (planeNormal.Z*planeLocation.Z)); float dot3 = (planeNormal.X*(line.Point2.X-line.Point1.X)) + (planeNormal.Y*(line.Point2.Y-line.Point1.Y)) + (planeNormal.Z*(line.Point2.Z-line.Point1.Z)); float dot2 = -((dot + (planeNormal.X*line.Point1.X) + (planeNormal.Y*line.Point1.Y) + (planeNormal.Z*line.Point1.Z)) / dot3); result = (line.Point1 + (dot2*(line.Point2-line.Point1))); }
public Vector3 InersectPlane(Vector3 planeNormal, Vector3 planeLocation) { float dot = (-(planeNormal.X*planeLocation.X) - (planeNormal.Y*planeLocation.Y) - (planeNormal.Z*planeLocation.Z)); float dot3 = (planeNormal.X*(Point2.X-Point1.X)) + (planeNormal.Y*(Point2.Y-Point1.Y)) + (planeNormal.Z*(Point2.Z-Point1.Z)); float dot2 = -((dot + (planeNormal.X*Point1.X) + (planeNormal.Y*Point1.Y) + (planeNormal.Z*Point1.Z)) / dot3); return (Point1 + (dot2*(Point2-Point1))); }
public InstanceObject(Object o) { Object = o; Position = o.Position; Scale = o.Scale; Rotation = o.Rotation; }
public Camera(IViewPort viewPort, Vector3 position, Vector3 lookAtPosition, Vector3 upPosition, float near, float far, float fov) { ViewPort = viewPort; Position = position; LookAtPosition = lookAtPosition; UpPosition = upPosition; Near = near; Far = far; Fov = fov; Aspect = float.NaN; }
public Camera(IViewPort viewPort, Vector3 position, Vector3 lookAtPosition, Vector3 upPosition) { ViewPort = viewPort; Position = position; LookAtPosition = lookAtPosition; UpPosition = upPosition; Near = 1; Far = 500; Fov = MathUtilities.DegToRad(45); Aspect = float.NaN; }
public Camera(IViewPort viewPort) { ViewPort = viewPort; Position = new Vector3(10, 10, 10); LookAtPosition = new Vector3(0, 0, 0); UpPosition = new Vector3(10, 11, 10); Near = 1; Far = 500; Fov = MathUtilities.DegToRad(45); Aspect = float.NaN; }
public Bone(BinaryReader reader) { Name = reader.ReadString(); parentName = reader.ReadString(); InheritScale = reader.ReadBoolean(); InheritRotation = reader.ReadBoolean(); Position = reader.ReadVector3(); RotationMatrix = reader.ReadMatrix3(); Rotation = Quaternion.FromMatrix3(RotationMatrix); }
public SoftwareBone(RMX_ArmatureBone bone) { Name = bone.Name; InheritScale = bone.InheritScale; InheritRotation = bone.InheritRotation; Position = new Vector3(bone.Position.Values[0], bone.Position.Values[1], bone.Position.Values[2]); Rotation = new Matrix3 ( new Vector3(bone.Rotation.Values[0], bone.Rotation.Values[1], bone.Rotation.Values[2]), new Vector3(bone.Rotation.Values[3], bone.Rotation.Values[4], bone.Rotation.Values[5]), new Vector3(bone.Rotation.Values[6], bone.Rotation.Values[7], bone.Rotation.Values[8]) ); }
public SoftwareObject(SoftwareModel model, RMX_Object o) { Model = model; Name = o.Name; // transform foreach (var input in o.Transform.Inputs) { switch (input.Type) { case "EulerRotation": Rotation = new Vector3(input.Values[0], input.Values[1], input.Values[2]); break; case "Scale": Scale = new Vector3(input.Values[0], input.Values[1], input.Values[2]); break; case "Position": Position = new Vector3(input.Values[0], input.Values[1], input.Values[2]); break; default: Debug.ThrowError("SoftwareMesh", "Unsuported Transform Type: " + input.Type); break; } } // find action if (o.DefaultAction != null) { foreach (var action in model.Actions) { if (o.DefaultAction.Name == action.Name) { DefaultAction = action; break; } } if (DefaultAction == null) Debug.ThrowError("SoftwareObjectArmature", "Failed to find Action: " + o.DefaultAction.Name); } // bone groups BoneGroups = new List<SoftwareObjectBoneGroup>(); if (o.BoneGroups != null) { foreach (var bonegroup in o.BoneGroups.BoneGroups) { BoneGroups.Add(new SoftwareObjectBoneGroup(bonegroup)); } } }
public RigidTransform3(Vector3 position) { Position = position; Orientation = Quaternion.Identity; }
public RigidTransform3(Quaternion orienation) { Position = new Vector3(); Orientation = orienation; }
public VertexProcessor(SoftwareVertex vertex, Vector4[] colors, Vector3[] normals, Vector2[] uvs, HardwareMeshProcessor mesh) { Positions = new Vector3[mesh.positions.Count]; for (int i = 0; i != Positions.Length; ++i) { Positions[i] = mesh.positions[i][vertex.Index]; } Colors = colors; Normals = normals; UVs = uvs; mesh.Verticies.AddLast(this); }
public RigidTransform3(Quaternion orienation, Vector3 position) { Orientation = orienation; Position = position; }
public TriangleProcessor(SoftwareTriangle triangle, HardwareMeshProcessor mesh, bool loadColors, bool loadUVs, bool loadNormals) { // get color components var colors = new Vector4[3][]; if (loadColors) { int componentCount = mesh.colorComponents.Count; for (int i = 0; i != colors.Length; ++i) { colors[i] = new Vector4[componentCount]; } for (int i = 0; i != componentCount; ++i) { var colorComponent = mesh.colorComponents[i][triangle.Index].Colors; colors[0][i] = colorComponent[0]; colors[1][i] = colorComponent[1]; colors[2][i] = colorComponent[2]; } } // get normal components var normals = new Vector3[3][]; if (loadNormals) { int componentCount = mesh.normalComponents.Count; for (int i = 0; i != normals.Length; ++i) { normals[i] = new Vector3[componentCount]; } for (int i = 0; i != componentCount; ++i) { var normalComponent = mesh.normalComponents[i][triangle.Index].Normals; normals[0][i] = normalComponent[0]; normals[1][i] = normalComponent[1]; normals[2][i] = normalComponent[2]; } } // get uv components var uvs = new Vector2[3][]; if (loadUVs) { int componentCount = mesh.uvComponents.Count; for (int i = 0; i != uvs.Length; ++i) { uvs[i] = new Vector2[componentCount]; } for (int i = 0; i != componentCount; ++i) { var normalComponent = mesh.uvComponents[i][triangle.Index].UVs; uvs[0][i] = normalComponent[0]; uvs[1][i] = normalComponent[1]; uvs[2][i] = normalComponent[2]; } } // add verticies var vertex1 = new VertexProcessor(triangle.Verticies[0], colors[0], normals[0], uvs[0], mesh); var vertex2 = new VertexProcessor(triangle.Verticies[1], colors[1], normals[1], uvs[1], mesh); var vertex3 = new VertexProcessor(triangle.Verticies[2], colors[2], normals[2], uvs[2], mesh); Verticies = new VertexProcessor[3] {vertex1, vertex2, vertex3}; mesh.Triangles.Add(this); }
public HardwareMeshProcessor(SoftwareMesh mesh, bool loadColors, bool loadUVs, bool loadNormals) { this.mesh = mesh; // get vertex component types positions = new List<Vector3[]>(); foreach (var key in mesh.VertexComponentKeys) { switch (key.Key) { case VertexComponentKeyTypes.Positions: var vertexComponents = mesh.VetexComponents[key.Value]; if (vertexComponents.GetType() == typeof(Vector3[])) { positions.Add((Vector3[])vertexComponents); } else if (vertexComponents.GetType() == typeof(Vector2[])) { var verts = (Vector2[])vertexComponents; var newVerts = new Vector3[verts.Length]; for (int i = 0; i != verts.Length; ++i) newVerts[i] = new Vector3(verts[i].X, verts[i].Y, 0); positions.Add(newVerts); } else { Debug.ThrowError("HardwareMeshProcessor", "Unsuported VectorComponent type"); } break; } } // get triangle component types if (loadColors) colorComponents = new List<TriangleColorComponent[]>(); if (loadNormals) normalComponents = new List<TriangleNormalComponent[]>(); if (loadUVs) uvComponents = new List<TriangleUVComponent[]>(); foreach (var key in mesh.TriangleComponentKeys) { switch (key.Key) { case TriangleComponentKeyTypes.ColorComponents: if (loadColors) colorComponents.Add((TriangleColorComponent[])mesh.TriangleComponents[key.Value]); break; case TriangleComponentKeyTypes.NormalComponents: if (loadNormals) normalComponents.Add((TriangleNormalComponent[])mesh.TriangleComponents[key.Value]); break; case TriangleComponentKeyTypes.UVComponents: if (loadUVs) uvComponents.Add((TriangleUVComponent[])mesh.TriangleComponents[key.Value]); break; } } // create triangles with there own verticies Verticies = new LinkedList<VertexProcessor>(); Triangles = new List<TriangleProcessor>(); foreach (var triangle in mesh.Triangles) { var newTriangle = new TriangleProcessor(triangle, this, loadColors, loadUVs, loadNormals); } // process (remove duplicate verticies from triangles) const float tolerance = .002f; int count = Triangles.Count-1, count2 = Triangles.Count; for (int i = 0; i != count; ++i) { for (int vi = 0; vi != 3; ++vi) { var vertex = Triangles[i].Verticies[vi]; for (int i2 = i+1; i2 != count2; ++i2) { for (int vi2 = 0; vi2 != 3; ++vi2) { var vertex2 = Triangles[i2].Verticies[vi2]; if (vertex == vertex2) continue; // position tolerance bool canRemoveVertex = true; for (int pi = 0; pi != vertex.Positions.Length; ++pi) { if (!vertex.Positions[pi].AproxEqualsBox(vertex2.Positions[pi], tolerance)) { canRemoveVertex = false; break; } } // color tolerance if (canRemoveVertex && loadColors) { for (int pi = 0; pi != vertex.Colors.Length; ++pi) { if (!vertex.Colors[pi].AproxEqualsBox(vertex2.Colors[pi], tolerance)) { canRemoveVertex = false; break; } } } // normal tolerance if (canRemoveVertex && loadNormals) { for (int pi = 0; pi != vertex.Normals.Length; ++pi) { if (!vertex.Normals[pi].AproxEqualsBox(vertex2.Normals[pi], tolerance)) { canRemoveVertex = false; break; } } } // uv tolerance if (canRemoveVertex && loadUVs) { for (int pi = 0; pi != vertex.UVs.Length; ++pi) { if (!vertex.UVs[pi].AproxEqualsBox(vertex2.UVs[pi], tolerance)) { canRemoveVertex = false; break; } } } // remove vertex if (canRemoveVertex) { Verticies.Remove(vertex2); Triangles[i2].Verticies[vi2] = vertex; } } } } } // process (set vertex indicies) int index = 0; foreach (var vertex in Verticies) { vertex.Index = index; ++index; } }
public void RotateGeometry(float x, float y, float z) { var mat = Matrix3.FromEuler(x, y, z); Position = Position.Transform(mat); }
public void RotateAroundUpPositionWorld(Vector3 radians) { var matrix = Matrix3.Identity; matrix = matrix.RotateAroundWorldAxisX(radians.X); matrix = matrix.RotateAroundWorldAxisY(radians.Y); matrix = matrix.RotateAroundWorldAxisZ(radians.Z); LookAtPosition -= UpPosition; LookAtPosition = LookAtPosition.Transform(matrix); LookAtPosition += UpPosition; Position -= UpPosition; Position = Position.Transform(matrix); Position += UpPosition; }
public Plane3(Vector3 normal, float distance) { Normal = normal; Distance = distance; }
public void Rotate(Line3 pLine, float radians) { var vector = (pLine.Point2 - pLine.Point1).NormalizeSafe(); Position -= pLine.Point1; LookAtPosition -= pLine.Point1; UpPosition -= pLine.Point1; Position = Position.RotateAround(vector, radians); LookAtPosition = LookAtPosition.RotateAround(vector, radians); UpPosition = UpPosition.RotateAround(vector, radians); Position += pLine.Point1; LookAtPosition += pLine.Point1; UpPosition += pLine.Point1; }
public float DotCoordinate(Vector3 vector) { return (Normal.X * vector.X) + (Normal.Y * vector.Y) + (Normal.Z * vector.Z) + Distance; }
public void RotateAroundUpPosition(Vector3 radians) { var matrix = Matrix3.LookAt((LookAtPosition - Position), (UpPosition - Position)); var matrixTranspose = matrix.Transpose(); matrix = matrix.RotateAroundAxisX(radians.X); matrix = matrix.RotateAroundAxisY(radians.Y); matrix = matrix.RotateAroundAxisZ(radians.Z); LookAtPosition -= UpPosition; LookAtPosition = LookAtPosition.Transform(matrixTranspose); LookAtPosition = LookAtPosition.Transform(matrix); LookAtPosition += UpPosition; Position -= UpPosition; Position = Position.Transform(matrixTranspose); Position = Position.Transform(matrix); Position += UpPosition; }
public void Offset(Vector3 value) { Position += value; LookAtPosition += value; UpPosition += value; }
public TriangleNormalComponent(Vector3 normal1, Vector3 normal2, Vector3 normal3) { Normals = new Vector3[3] {normal1, normal2, normal3}; }
public static void DotCoordinate(ref Plane3 plane, ref Vector3 vector, out float result) { result = (plane.Normal.X * vector.X) + (plane.Normal.Y * vector.Y) + (plane.Normal.Z * vector.Z) + plane.Distance; }
public Line3(Vector3 point1, Vector3 point2) { Point1 = point1; Point2 = point2; }
public void Zoom(float value, float stopRadis) { var vec = (LookAtPosition - Position); float dis = 0; vec = vec.Normalize(out dis); dis = ((dis-stopRadis) - value); if (dis < 0) value += dis; vec *= value; Position += vec; UpPosition += vec; }
public void Rotate(float x, float y, float z) { Rotation += new Vector3(x, y, z); }
public Vector2 Project(Vector3 position) { var pos = new Vector4(position, 1); return pos.Project(ProjectionMatrix, ViewMatrix, ViewPort.Position.X, ViewPort.Position.Y, ViewPort.Size.Width, ViewPort.Size.Height).ToVector2(); }