public BoxModel() { Position = new MyVector3(); Rotation = new MyVector3(); Scale = new MyVector3(1, 1, 1); Name = "Box_" + BOX_COUNT; BOX_COUNT++; }
public OvmModel(string path) { SetName(path); _path = path; Scale = new MyVector3(1, 1, 1) ; Rotation = new MyVector3(); Position = new MyVector3(); }
/** * Sets the constant acceleration of the particle. */ public void SetAcceleration(MyVector3 acceleration) { this.acceleration = acceleration; }
/** * Sets the velocity of the particle. */ public void SetVelocity(MyVector3 velocity) { this.velocity = velocity; }
/** * Fills the given vector with the position of the particle. * * @param position A pointer to a vector into which to write * the position. */ public void GetPosition(MyVector3 position) { position = this.position; }
/*Creates generator with given acceleration*/ public ParticleGravity(MyVector3 grav) { this.gravity = grav; }
/// <summary> /// Determines if there is an intersection between the current object and a point. /// </summary> /// <param name="point">The point to test.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyVector3 point) { return(MyCollision.RayIntersectsPoint(ref this, ref point)); }
public static MyVector3 Cross(MyVector3 lhs, MyVector3 rhs) { return(new MyVector3(lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z, lhs.x * rhs.y - lhs.y * rhs.x)); }
public void SetScale(MyVector3 scale) { var UndoCommand = new RelayCommand<MyVector3>(undoSetScale); MyVector3 parameter = new MyVector3(); parameter.Vector3 = Scale.Vector3; UndoRedoStack.AddRedoCommand(UndoCommand, parameter); Scale.Vector3 = scale.Vector3; }
/// <summary> /// Scales the <see cref="MyOrientedBoundingBox"/> by scaling its Extents without affecting the Transformation matrix, /// By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate. /// </summary> /// <param name="scaling"></param> public void Scale(float scaling) { Extents *= scaling; }
/// <summary> /// Scales the <see cref="MyOrientedBoundingBox"/> by scaling its Extents without affecting the Transformation matrix, /// By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate. /// </summary> /// <param name="scaling"></param> public void Scale(MyVector3 scaling) { Extents *= scaling; }
public void StartVisualizer(HalfEdgeData3 halfEdgeMeshData, int maxEdgesToContract, float maxError, bool normalizeTriangles = false) { controller = GetComponent <VisualizerController3D>(); // // Compute the Q matrices for all the initial vertices // //Put the result in a lookup dictionary //This assumes we have no floating point precision issues, so vertices at the same position have to be at the same position Dictionary <MyVector3, Matrix4x4> qMatrices = new Dictionary <MyVector3, Matrix4x4>(); HashSet <HalfEdgeVertex3> vertices = halfEdgeMeshData.verts; //timer.Start(); //0.142 seconds for the bunny (0.012 for dictionary lookup, 0.024 to calculate the Q matrices, 0.087 to find edges going to vertex) foreach (HalfEdgeVertex3 v in vertices) { //Have we already calculated a Q matrix for this vertex? //Remember that we have multiple vertices at the same position in the half-edge data structure //timer.Start(); if (qMatrices.ContainsKey(v.position)) { continue; } //timer.Stop(); //Calculate the Q matrix for this vertex //timer.Start(); //Find all edges meeting at this vertex HashSet <HalfEdge3> edgesPointingToThisVertex = v.GetEdgesPointingToVertex(halfEdgeMeshData); //timer.Stop(); //timer.Start(); Matrix4x4 Q = MeshSimplification_QEM.CalculateQMatrix(edgesPointingToThisVertex, normalizeTriangles); //timer.Stop(); qMatrices.Add(v.position, Q); } //timer.Stop(); // // Select all valid pairs that can be contracted // List <HalfEdge3> validPairs = new List <HalfEdge3>(halfEdgeMeshData.edges); // // Compute the cost of contraction for each pair // HashSet <QEM_Edge> QEM_edges = new HashSet <QEM_Edge>(); //We need a lookup table to faster remove and update QEM_edges Dictionary <HalfEdge3, QEM_Edge> halfEdge_QEM_Lookup = new Dictionary <HalfEdge3, QEM_Edge>(); foreach (HalfEdge3 halfEdge in validPairs) { MyVector3 p1 = halfEdge.prevEdge.v.position; MyVector3 p2 = halfEdge.v.position; Matrix4x4 Q1 = qMatrices[p1]; Matrix4x4 Q2 = qMatrices[p2]; QEM_Edge QEM_edge = new QEM_Edge(halfEdge, Q1, Q2); QEM_edges.Add(QEM_edge); halfEdge_QEM_Lookup.Add(halfEdge, QEM_edge); } // // Sort all pairs, with the minimum cost pair at the top // //The fastest way to keep the data sorted is to use a heap Heap <QEM_Edge> sorted_QEM_edges = new Heap <QEM_Edge>(QEM_edges.Count); foreach (QEM_Edge e in QEM_edges) { sorted_QEM_edges.Add(e); } //Main visualization algorithm coroutine StartCoroutine(QEMLoop(halfEdgeMeshData, sorted_QEM_edges, qMatrices, halfEdge_QEM_Lookup, maxEdgesToContract, maxError, normalizeTriangles)); }
public static MyVector3 Scale(MyVector3 lhs, MyVector3 rhs) { return(new MyVector3(lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z)); }
public static float Dot(MyVector3 lhs, MyVector3 rhs) { return(lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z); }
public static float Distance(MyVector3 lhs, MyVector3 rhs) { return((lhs - rhs).magnitude); }
public void SetPosition(MyVector3 position) { var UndoCommand = new RelayCommand<MyVector3>(undoSetPosition); MyVector3 parameter = new MyVector3(); parameter.Vector3 = Position.Vector3; UndoRedoStack.AddRedoCommand(UndoCommand, parameter); Position.Vector3 = position.Vector3; }
/// <summary> /// Translates the <see cref="MyOrientedBoundingBox"/> to a new position using a translation vector; /// </summary> /// <param name="translation">the translation vector.</param> public void Translate(MyVector3 translation) { Transformation.TranslationVector += translation; }
public void SetRotation(MyVector3 rotation) { var UndoCommand = new RelayCommand<MyVector3>(undoSetRotation); MyVector3 parameter = new MyVector3(); parameter.Vector3 = RotationEuler.Vector3; UndoRedoStack.AddRedoCommand(UndoCommand, parameter); RotationEuler.Vector3 = rotation.Vector3; }
/// <summary> /// Determines whether a <see cref="MyOrientedBoundingBox"/> contains a point. /// </summary> /// <param name="point">The point to test.</param> /// <returns>The type of containment the two objects have.</returns> public MyContainmentType Contains(MyVector3 point) { return Contains(ref point); }
/// <summary> /// Initializes a new instance of the <see cref="MyRay"/> struct. /// </summary> /// <param name="position">The position in three dimensional space of the origin of the ray.</param> /// <param name="direction">The normalized direction of the ray.</param> public MyRay(MyVector3 position, MyVector3 direction) { this.Position = position; this.Direction = direction; }
/// <summary> /// Check the intersection between two <see cref="MyOrientedBoundingBox"/> /// </summary> /// <param name="obb">The OrientedBoundingBoxs to test.</param> /// <returns>The type of containment the two objects have.</returns> /// <remarks> /// For accuracy, The transformation matrix for both <see cref="MyOrientedBoundingBox"/> must not have any scaling applied to it. /// Anyway, scaling using Scale method will keep this method accurate. /// </remarks> public MyContainmentType Contains(ref MyOrientedBoundingBox obb) { var cornersCheck = Contains(obb.GetCorners()); if (cornersCheck != MyContainmentType.Disjoint) return cornersCheck; //http://www.3dkingdoms.com/weekly/bbox.cpp var SizeA = Extents; var SizeB = obb.Extents; var RotA = GetRows(ref Transformation); var RotB = GetRows(ref obb.Transformation); var R = new MyMatrix(); // Rotation from B to A var AR = new MyMatrix(); // absolute values of R matrix, to use with box extents float ExtentA, ExtentB, Separation; int i, k; // Calculate B to A rotation matrix for (i = 0; i < 3; i++) for (k = 0; k < 3; k++) { R[i, k] = MyVector3.Dot(RotA[i], RotB[k]); AR[i, k] = Math.Abs(R[i, k]); } // Vector separating the centers of Box B and of Box A var vSepWS = obb.Center - Center; // Rotated into Box A's coordinates var vSepA = new MyVector3(MyVector3.Dot(vSepWS, RotA[0]), MyVector3.Dot(vSepWS, RotA[1]), MyVector3.Dot(vSepWS, RotA[2])); // Test if any of A's basis vectors separate the box for (i = 0; i < 3; i++) { ExtentA = SizeA[i]; ExtentB = MyVector3.Dot(SizeB, new MyVector3(AR[i, 0], AR[i, 1], AR[i, 2])); Separation = Math.Abs(vSepA[i]); if (Separation > ExtentA + ExtentB) return MyContainmentType.Disjoint; } // Test if any of B's basis vectors separate the box for (k = 0; k < 3; k++) { ExtentA = MyVector3.Dot(SizeA, new MyVector3(AR[0, k], AR[1, k], AR[2, k])); ExtentB = SizeB[k]; Separation = Math.Abs(MyVector3.Dot(vSepA, new MyVector3(R[0, k], R[1, k], R[2, k]))); if (Separation > ExtentA + ExtentB) return MyContainmentType.Disjoint; } // Now test Cross Products of each basis vector combination ( A[i], B[k] ) for (i = 0; i < 3; i++) for (k = 0; k < 3; k++) { int i1 = (i + 1) % 3, i2 = (i + 2) % 3; int k1 = (k + 1) % 3, k2 = (k + 2) % 3; ExtentA = SizeA[i1] * AR[i2, k] + SizeA[i2] * AR[i1, k]; ExtentB = SizeB[k1] * AR[i, k2] + SizeB[k2] * AR[i, k1]; Separation = Math.Abs(vSepA[i2] * R[i1, k] - vSepA[i1] * R[i2, k]); if (Separation > ExtentA + ExtentB) return MyContainmentType.Disjoint; } // No separating axis found, the boxes overlap return MyContainmentType.Intersects; }
private void ProjectPointToCanvas3(MyVector2 screenpt, MyVector3 c, MyVector3 nor, out MyVector3 v, out double r) { if (this.glProjector == null) { this.ObtainGLProjector(); } screenpt.y = this.view.Height - screenpt.y; // the out parameter r measures how close the intersecting point is to the near Canvas3' // 1. get transformed Canvas3 normal and center (due to view point change) MyVector3 s = this.glProjector.UnProject(screenpt.x, screenpt.y, -1); MyVector3 t = this.glProjector.UnProject(screenpt.x, screenpt.y, 1); r = (c - t).Dot(nor) / ((s - t).Dot(nor)); v = r * s + (1 - r) * t; }
/// <summary> /// Creates an <see cref="MyOrientedBoundingBox"/> from a BoundingBox. /// </summary> /// <param name="bb">The BoundingBox to create from.</param> /// <remarks> /// Initially, the OBB is axis-aligned box, but it can be rotated and transformed later. /// </remarks> public MyOrientedBoundingBox(MyBoundingBox bb) { var Center = bb.Minimum + (bb.Maximum - bb.Minimum) / 2f; Extents = bb.Maximum - Center; Transformation = MyMatrix.Translation(Center); }
/** * Sets the position of the particle. * * @param position The new position of the particle. */ public void SetPosition(MyVector3 position) { this.position = position; }
/// <summary> /// Check the intersection between an <see cref="MyOrientedBoundingBox"/> and <see cref="MyBoundingBox"/> /// </summary> /// <param name="box">The BoundingBox to test.</param> /// <returns>The type of containment the two objects have.</returns> /// <remarks> /// For accuracy, The transformation matrix for the <see cref="MyOrientedBoundingBox"/> must not have any scaling applied to it. /// Anyway, scaling using Scale method will keep this method accurate. /// </remarks> public MyContainmentType Contains(ref MyBoundingBox box) { var cornersCheck = Contains(box.GetCorners()); if (cornersCheck != MyContainmentType.Disjoint) return cornersCheck; var boxCenter = box.Minimum + (box.Maximum - box.Minimum) / 2f; var boxExtents = box.Maximum - boxCenter; var SizeA = Extents; var SizeB = boxExtents; var RotA = GetRows(ref Transformation); float ExtentA, ExtentB, Separation; int i, k; MyMatrix R; // Rotation from B to A MyMatrix.Invert(ref Transformation, out R); var AR = new MyMatrix(); // absolute values of R matrix, to use with box extents for (i = 0; i < 3; i++) for (k = 0; k < 3; k++) { AR[i, k] = Math.Abs(R[i, k]); } // Vector separating the centers of Box B and of Box A var vSepWS = boxCenter - Center; // Rotated into Box A's coordinates var vSepA = new MyVector3(MyVector3.Dot(vSepWS, RotA[0]), MyVector3.Dot(vSepWS, RotA[1]), MyVector3.Dot(vSepWS, RotA[2])); // Test if any of A's basis vectors separate the box for (i = 0; i < 3; i++) { ExtentA = SizeA[i]; ExtentB = MyVector3.Dot(SizeB, new MyVector3(AR[i, 0], AR[i, 1], AR[i, 2])); Separation = Math.Abs(vSepA[i]); if (Separation > ExtentA + ExtentB) return MyContainmentType.Disjoint; } // Test if any of B's basis vectors separate the box for (k = 0; k < 3; k++) { ExtentA = MyVector3.Dot(SizeA, new MyVector3(AR[0, k], AR[1, k], AR[2, k])); ExtentB = SizeB[k]; Separation = Math.Abs(MyVector3.Dot(vSepA, new MyVector3(R[0, k], R[1, k], R[2, k]))); if (Separation > ExtentA + ExtentB) return MyContainmentType.Disjoint; } // Now test Cross Products of each basis vector combination ( A[i], B[k] ) for (i = 0; i < 3; i++) for (k = 0; k < 3; k++) { int i1 = (i + 1) % 3, i2 = (i + 2) % 3; int k1 = (k + 1) % 3, k2 = (k + 2) % 3; ExtentA = SizeA[i1] * AR[i2, k] + SizeA[i2] * AR[i1, k]; ExtentB = SizeB[k1] * AR[i, k2] + SizeB[k2] * AR[i, k1]; Separation = Math.Abs(vSepA[i2] * R[i1, k] - vSepA[i1] * R[i2, k]); if (Separation > ExtentA + ExtentB) return MyContainmentType.Disjoint; } // No separating axis found, the boxes overlap return MyContainmentType.Intersects; }
/** * Fills the given vector with the velocity of the particle. */ public void GetVelocity(MyVector3 velocity) { velocity = this.velocity; }
/// <summary> /// Creates an <see cref="MyOrientedBoundingBox"/> which contained between two minimum and maximum points. /// </summary> /// <param name="minimum">The minimum vertex of the bounding box.</param> /// <param name="maximum">The maximum vertex of the bounding box.</param> /// <remarks> /// Initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later. /// </remarks> public MyOrientedBoundingBox(MyVector3 minimum, MyVector3 maximum) { var Center = minimum + (maximum - minimum) / 2f; Extents = maximum - Center; Transformation = MyMatrix.Translation(Center); }
/** * Fills the given vector with the acceleration of the particle. */ public void GetAcceleration(MyVector3 acceleration) { acceleration = this.acceleration; }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyRay"/>. /// </summary> /// <param name="ray">The ray to test.</param> /// <param name="point">When the method completes, contains the point of intersection, /// or <see cref="MyVector3.Zero"/> if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyRay ray, out MyVector3 point) { return(MyCollision.RayIntersectsRay(ref this, ref ray, out point)); }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyPlane"/>. /// </summary> /// <param name="plane">The plane to test.</param> /// <param name="point">When the method completes, contains the point of intersection, /// or <see cref="MyVector3.Zero"/> if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyPlane plane, out MyVector3 point) { return(MyCollision.RayIntersectsPlane(ref this, ref plane, out point)); }
/// <summary> /// Determines if there is an intersection between the current object and a triangle. /// </summary> /// <param name="vertex1">The first vertex of the triangle to test.</param> /// <param name="vertex2">The second vertex of the triangle to test.</param> /// <param name="vertex3">The third vertex of the triangle to test.</param> /// <param name="distance">When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyVector3 vertex1, ref MyVector3 vertex2, ref MyVector3 vertex3, out float distance) { return(MyCollision.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out distance)); }
//**********************************// // METHODS // //**********************************// public TransformComponent() { Position = new MyVector3(0, 0, 0); WorldPosition = new MyVector3(0, 0, 0); Scale = new MyVector3(1, 1, 1); WorldScale = new MyVector3(1, 1, 1); Rotation = new Quaternion(0,0,0,1); WorldRotation = new Quaternion(0, 0, 0,1); RotationEuler = new MyVector3(0, 0, 0); WorldRotationEuler = new MyVector3(0, 0, 0); Forward = new MyVector3(0, 0, 1); Up = new MyVector3(0, 1, 0); Right = new MyVector3(1, 0, 0); //Update(); }
/// <summary> /// Determines if there is an intersection between the current object and a triangle. /// </summary> /// <param name="vertex1">The first vertex of the triangle to test.</param> /// <param name="vertex2">The second vertex of the triangle to test.</param> /// <param name="vertex3">The third vertex of the triangle to test.</param> /// <param name="point">When the method completes, contains the point of intersection, /// or <see cref="MyVector3.Zero"/> if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyVector3 vertex1, ref MyVector3 vertex2, ref MyVector3 vertex3, out MyVector3 point) { return(MyCollision.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out point)); }
private void undoSetPosition(MyVector3 position) { var redoCommand = new RelayCommand<MyVector3>(SetPosition); MyVector3 parameter = new MyVector3(); parameter.Vector3 = Position.Vector3; UndoRedoStack.AddUndoCommand(redoCommand, parameter); Position.Vector3 = position.Vector3; }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyBoundingBox"/>. /// </summary> /// <param name="box">The box to test.</param> /// <param name="point">When the method completes, contains the point of intersection, /// or <see cref="MyVector3.Zero"/> if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyBoundingBox box, out MyVector3 point) { return(MyCollision.RayIntersectsBox(ref this, ref box, out point)); }
private void undoSetScale(MyVector3 scale) { var redoCommand = new RelayCommand<MyVector3>(SetScale); MyVector3 parameter = new MyVector3(); parameter.Vector3 = Scale.Vector3; UndoRedoStack.AddUndoCommand(redoCommand, parameter); Scale.Vector3 = scale.Vector3; }
/// <summary> /// Determines if there is an intersection between the current object and a <see cref="MyBoundingSphere"/>. /// </summary> /// <param name="sphere">The sphere to test.</param> /// <param name="point">When the method completes, contains the point of intersection, /// or <see cref="MyVector3.Zero"/> if there was no intersection.</param> /// <returns>Whether the two objects intersected.</returns> public bool Intersects(ref MyBoundingSphere sphere, out MyVector3 point) { return(MyCollision.RayIntersectsSphere(ref this, ref sphere, out point)); }
private void undoSetRotation(MyVector3 rotation) { var redoCommand = new RelayCommand<MyVector3>(SetRotation); MyVector3 parameter = new MyVector3(); parameter.Vector3 = RotationEuler.Vector3; UndoRedoStack.AddUndoCommand(redoCommand, parameter); RotationEuler.Vector3 = rotation.Vector3; }
//Static Methods public static float Angle(MyVector3 from, MyVector3 to) { //return Mathf.Acos(Dot(from,to) / (from.magnitude * to.magnitude)); return(Mathf.Acos(Mathf.Clamp(Dot(from, to) / (from.magnitude * to.magnitude), -1f, 1f)) * 57.29578f); }