Пример #1
0
 public Box3D(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax)
 {
     MinEdge = new Vector3D();
     MaxEdge = new Vector3D();
     MinEdge.Set(xMin, yMin, zMin);
     MaxEdge.Set(xMax, yMax, zMax);
 }
Пример #2
0
 public Vertex3D(Vector3D position, Vector3D normal, Color color, Vector2D tcoord)
     : this()
 {
     Position = position;
     Normal = normal;
     Color = color;
     TCoords = tcoord;
 }
Пример #3
0
 public Vector3D GetCollisionResultPoint(TriangleSelector selector, Vector3D ellipsoidPosition, Vector3D ellipsoidRadius, Vector3D ellipsoidDirectionAndSpeed, out Triangle3D outTriangle, out bool outFalling, float slidingSpeed, Vector3D gravityDirectionAndSpeed)
 {
     float[] outtri = new float[9];
     float[] outpos = new float[3];
     outFalling = false;
     SceneCollisionManager_GetCollisionResultPoint(_raw, selector.Raw, ellipsoidPosition.ToUnmanaged(), ellipsoidRadius.ToUnmanaged(), ellipsoidDirectionAndSpeed.ToUnmanaged(), outtri, ref outFalling, slidingSpeed, gravityDirectionAndSpeed.ToUnmanaged(), outpos);
     outTriangle = Triangle3D.FromUnmanaged(outtri);
     return Vector3D.FromUnmanaged(outpos);
 }
Пример #4
0
 public bool GetCollisionPoint(Line3D ray, TriangleSelector selector, out Vector3D collisionPoint, out Triangle3D collisionTriangle)
 {
     float[] colp = new float[3];
     float[] coltri = new float[9];
     bool toR = SceneCollisionManager_GetCollisionPoint(_raw, ray.ToUnmanaged(), selector.Raw, colp, coltri);
     collisionPoint = Vector3D.FromUnmanaged(colp);
     collisionTriangle = Triangle3D.FromUnmanaged(coltri);
     return toR;
 }
Пример #5
0
        public Vector3D GetClosestPoint(Vector3D point)
        {
            Vector3D c = point - Start;
            Vector3D v = End - Start;
            float d = v.Length;
            v = v / d;
            float t = v.DotProduct(c);

            if (t < 0.0f) return Start;
            if (t > d) return End;

            v = v * t;
            return Start + v;
        }
        public TextSceneNode AddBillboardTextSceneNodeW(GUIFont font, string text, SceneNode parent, Dimension2Df size, Vector3D position, int id, Color shade_top, Color shade_down)
        {
#if !LINUX
            return (TextSceneNode)
                NativeElement.GetObject(SceneManager_AddTextSceneNode2W(_raw, font.Raw, text, GetPtr(parent), size.ToUnmanaged(), position.ToUnmanaged(),
                                                                id, shade_top.ToUnmanaged(), shade_down.ToUnmanaged()),
                                        typeof(TextSceneNode));
#else
            return (TextSceneNode)
                NativeElement.GetObject(SceneManager_AddTextSceneNode2(_raw, font.Raw, text, GetPtr(parent), size.ToUnmanaged(), position.ToUnmanaged(),
                                                                id, shade_top.ToUnmanaged(), shade_down.ToUnmanaged()),
                                        typeof(TextSceneNode));
#endif
        }
Пример #7
0
        public bool GetIntersectionWithSphere(Vector3D sorigin, float sradius, out double outdistance)
        {
            outdistance = 0.0;
            Vector3D q = sorigin - Start;
            double c = q.Length;
            Vector3D vv = Vector;
            vv.Normalize();
            double v = q.DotProduct(vv);
            double d = sradius * sradius - (c * c - v * v);

            if (d < 0.0)
                return false;

            outdistance = v - Math.Sqrt(d);
            return true;
        }
Пример #8
0
 public Position2D GetScreenCoordinatesFrom3DPosition(Vector3D position, CameraSceneNode camera)
 {
     int[] sc = new int[2];
     SceneCollisionManager_GetScreenCoordinatesFrom3DPosition(_raw, position.ToUnmanaged(), GetPtr(camera), sc);
     return Position2D.FromUnmanaged(sc);
 }
Пример #9
0
        public Vector3D TransformVect(ref Vector3D vect)
        {
            float[] vector = { 0, 0, 0 };

            vector[0] = vect.X * M[0] + vect.Y * M[4] + vect.Z * M[8] + M[12];
            vector[1] = vect.X * M[1] + vect.Y * M[5] + vect.Z * M[9] + M[13];
            vector[2] = vect.X * M[2] + vect.Y * M[6] + vect.Z * M[10] + M[14];

            vect.X = vector[0];
            vect.Y = vector[1];
            vect.Z = vector[2];
            return vect;
        }
Пример #10
0
 public double DistanceFrom(Vector3D what)
 {
     return Math.Sqrt(DistanceFromSQ(what));
 }
Пример #11
0
 public double DistanceFromSQ(Vector3D what)
 {
     return (NewMath.Sqr(X - what.X) + NewMath.Sqr(Y - what.Y) + +NewMath.Sqr(Z - what.Z));
 }
Пример #12
0
 public ParticleEmitter CreatePointEmitter(Vector3D direction, uint minPPS, uint maxPPS, Color minSC, Color maxSC, uint minLT, uint maxLT, int maxAngleDegrees)
 {
     return (ParticleEmitter)
         NativeElement.GetObject(Particle_CreatePointEmitter(_raw, direction.ToUnmanaged(), minPPS, maxPPS, minSC.ToUnmanaged(), maxSC.ToUnmanaged(), minLT, maxLT, maxAngleDegrees),
                                 typeof(ParticleEmitter));
 }
Пример #13
0
 /// <summary>
 /// Scales the whole mesh.
 /// </summary>
 /// <param name="mesh">Mesh on which the operation is performed. </param>
 /// <param name="scale">Scale factor. </param>
 public void ScaleMesh(Mesh mesh, Vector3D scale)
 {
     MeshManipulator_ScaleMesh(_raw, mesh.Raw, scale.ToUnmanaged());
 }
Пример #14
0
        /// <summary> Builds a right-handed look-at matrix.</summary>
        public void BuildCameraLookAtMatrixRH(Vector3D position, Vector3D target, Vector3D upVector)
        {
            Vector3D zaxis = position - target;
            zaxis.Normalize();

            Vector3D xaxis = upVector.CrossProduct(zaxis);
            xaxis.Normalize();

            Vector3D yaxis = zaxis.CrossProduct(xaxis);

            SetMInsecure(0, 0, xaxis.X);
            SetMInsecure(1, 0, yaxis.X);
            SetMInsecure(2, 0, zaxis.X);
            SetMInsecure(3, 0, 0);

            SetMInsecure(0, 1, xaxis.Y);
            SetMInsecure(1, 1, yaxis.Y);
            SetMInsecure(2, 1, zaxis.Y);
            SetMInsecure(3, 1, 0);

            SetMInsecure(0, 2, xaxis.Z);
            SetMInsecure(1, 2, yaxis.Z);
            SetMInsecure(2, 2, zaxis.Z);
            SetMInsecure(3, 2, 0);

            SetMInsecure(0, 3, -xaxis.DotProduct(position));
            SetMInsecure(1, 3, -yaxis.DotProduct(position));
            SetMInsecure(2, 3, -zaxis.DotProduct(position));
            SetMInsecure(3, 3, 1.0f);
        }
Пример #15
0
 public Vector3D CrossProduct(Vector3D p)
 {
     return new Vector3D(Y * p.Z - Z * p.Y, Z * p.X - X * p.Z, X * p.Y - Y * p.X);
 }
Пример #16
0
 /// <summary>
 /// Adds a point to the bounding box, causing it to grow bigger,
 /// if point is outside of the box
 /// </summary>
 /// <param name="p"> Point to add into the box.</param>
 public void AddInternalPoint(Vector3D p)
 {
     AddInternalPoint(p.X, p.Y, p.Z);
 }
Пример #17
0
        public Vector3D GetInterpolated_Quadratic(Vector3D v2, Vector3D v3, float d)
        {
            float inv = 1.0f - d;
            float mul0 = inv * inv;
            float mul1 = (float)2.0 * d * inv;
            float mul2 = d * d;

            return new Vector3D(X * mul0 + v2.X * mul1 + v3.X * mul2,
                    Y * mul0 + v2.Y * mul1 + v3.Y * mul2,
                    Z * mul0 + v2.Z * mul1 + v3.Z * mul2);

        }
Пример #18
0
 public Box3D(Vector3D min, Vector3D max)
 {
     MinEdge = min;
     MaxEdge = max;
 }
Пример #19
0
        /// <summary>
        /// Stores all 8 edges of the box into a array
        /// </summary>
        /// <param name="edges">Aray of 8 edges</param>
        public void GetEdges(out Vector3D[] edges)
        {
            edges = new Vector3D[8];
            Vector3D middle = (MinEdge + MaxEdge) / 2;
            Vector3D diag = middle - MaxEdge;

            /*
             Edges are stored in this way:
             Hey, am I an ascii artist, or what? :) niko.
               /1--------/3
              / |       / |
             /  |      /  |
             5---------7  |
             |  0- - - | -2
             | /       |  /
             |/        | /
             4---------6/
             */

            edges[0].Set(middle.X + diag.X, middle.Y + diag.Y, middle.Z + diag.Z);
            edges[1].Set(middle.X + diag.X, middle.Y - diag.Y, middle.Z + diag.Z);
            edges[2].Set(middle.X + diag.X, middle.Y + diag.Y, middle.Z - diag.Z);
            edges[3].Set(middle.X + diag.X, middle.Y - diag.Y, middle.Z - diag.Z);
            edges[4].Set(middle.X - diag.X, middle.Y + diag.Y, middle.Z + diag.Z);
            edges[5].Set(middle.X - diag.X, middle.Y - diag.Y, middle.Z + diag.Z);
            edges[6].Set(middle.X - diag.X, middle.Y + diag.Y, middle.Z - diag.Z);
            edges[7].Set(middle.X - diag.X, middle.Y - diag.Y, middle.Z - diag.Z);
        }
Пример #20
0
 /// <summary>
 /// Determinates if a point is within this box and its borders.
 /// </summary>
 /// <param name="p"> Point to check.</param>
 /// <returns> Returns true if the point is withing the box, and false if it is not.</returns>
 public bool IsPointTotalInside(Vector3D p)
 {
     return (p.X > MinEdge.X && p.X < MaxEdge.X &&
         p.Y > MinEdge.Y && p.Y < MaxEdge.Y &&
         p.Z > MinEdge.Z && p.Z < MaxEdge.Z);
 }
Пример #21
0
 public void Draw3DLine(Vector3D start, Vector3D end, Color color)
 {
     VideoDriver_Draw3DLine(_raw, start.ToUnmanaged(), end.ToUnmanaged(), color.ToUnmanaged());
 }
Пример #22
0
 public bool IsBetweenPoints(Vector3D begin, Vector3D end)
 {
     float f = ((end - begin).LengthSQ);
     return DistanceFromSQ(begin) < f &&
            DistanceFromSQ(end) < f;
 }
Пример #23
0
 public Vertex3DTangents(Vector3D position, Vector3D normal, Color color,
                         Vector2D tcoord,
                         Vector3D binormal,
                         Vector3D tangent)
     : this()
 {
     Position = position;
     Normal = normal;
     Color = color;
     TCoords = tcoord;
     Binormal = binormal;
     Tangent = tangent;
 }
Пример #24
0
 //! axis must be unit length
 //! The Quaternion representing the rotation is
 //!  q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k)
 public void fromAngleAxis(float angle, Vector3D axis)
 {
     float fHalfAngle = 0.5f * angle;
     float fSin = (float)Math.Sin(fHalfAngle);
     m_w = (float)Math.Cos(fHalfAngle);
     m_x = fSin * axis.X;
     m_y = fSin * axis.Y;
     m_z = fSin * axis.Z;
 }
Пример #25
0
 public Vector3D RotateVect(ref Vector3D vect)
 {
     Vector3D tmp = new Vector3D(vect.X, vect.Y, vect.Z);
     vect.X = tmp.X * M[0] + tmp.Y * M[4] + tmp.Z * M[8];
     vect.Y = tmp.X * M[1] + tmp.Y * M[5] + tmp.Z * M[9];
     vect.Z = tmp.X * M[2] + tmp.Y * M[6] + tmp.Z * M[10];
     return vect;
 }
Пример #26
0
 public float DotProduct(Vector3D other)
 {
     return X * other.X + Y * other.Y + Z * other.Z;
 }
Пример #27
0
        //! multiplication operator by a vector
        public static Vector3D operator *(Vector3D lhs, Quaternion rhs)
        {
            Vector3D qvec = new Vector3D(rhs.X, rhs.Y, rhs.Z);
            Vector3D uv = qvec.CrossProduct(lhs);
            Vector3D uuv = qvec.CrossProduct(uv);
            uv *= (2.0f * rhs.W);
            uuv *= 2.0f;

            return lhs + uv + uuv;
        }
Пример #28
0
 /// <summary>
 /// Determinates if a point is within this box.
 /// </summary>
 /// <param name="p">: Point to check.</param>
 /// <returns> Returns true if the point is withing the box, and false if it is not.</returns>
 public bool IsPointInside(Vector3D p)
 {
     return (p.X >= MinEdge.X && p.X <= MaxEdge.X &&
         p.Y >= MinEdge.Y && p.Y <= MaxEdge.Y &&
         p.Z >= MinEdge.Z && p.Z <= MaxEdge.Z);
 }
Пример #29
0
        /// <summary>
        /// Returns an Euler Angles vector. Angles in radiants
        /// </summary>
        /// <param name="euler">vector to put the result into</param>
        /// <returns></returns>
        public Vector3D toEuler(out Vector3D euler)
        {
            double sqw = m_w * m_w;
            double sqx = m_x * m_x;
            double sqy = m_y * m_y;
            double sqz = m_z * m_z;

            // heading = rotation about z-axis
            euler.Z = (float)(Math.Atan2(2.0 * (m_x * m_y + m_z * m_w), (sqx - sqy - sqz + sqw)));

            // bank = rotation about x-axis
            euler.X = (float)(Math.Atan2(2.0 * (m_y * m_z + m_x * m_w), (-sqx - sqy + sqz + sqw)));

            // attitude = rotation about y-axis
            euler.Y = (float)(Math.Asin(-2.0 * (m_x * m_z - m_y * m_w)));
            return euler;
        }
Пример #30
0
 public ParticleAffector CreateGravityAffector(Vector3D gravity, uint timeForceLost)
 {
     return (ParticleAffector)
         NativeElement.GetObject(Particle_CreateGravityAffector(_raw, gravity.ToUnmanaged(), timeForceLost),
                                 typeof(ParticleAffector));
 }