Example #1
0
        public aVertex cross(aVertex operand)
        {
            aVertex toReturn = new aVertex();

            toReturn.set(y * operand.z - z * operand.y, z * operand.x - x * operand.z, x * operand.y - y * operand.x);
            return(toReturn);
        }
Example #2
0
        public static aVertex operator +(aVertex o1, aVertex o2)
        {
            aVertex toReturn = new aVertex();

            toReturn.set(o1.x + o2.x, o1.y + o2.y, o1.z + o2.z);
            return(toReturn);
        }
Example #3
0
        public static aVertex operator *(aVertex o1, float o2)
        {
            aVertex toReturn = new aVertex();

            toReturn.set(o1.x * o2, o1.y * o2, o1.z * o2);
            return(toReturn);
        }
Example #4
0
        public virtual void Update(float dt)
        {
            _location = _location + _linearVelocity * dt;
            kQuat operationalAngularVelocity = new kQuat(_angularVelocity);

            operationalAngularVelocity.scl = operationalAngularVelocity.scl * dt;
            if (_angularVelocity.scl == 0.0f || _angularVelocity.scl == 2.0 * Math.PI)
            {
                // No angular velocity; keep old orientation
            }
            else if (_orientation.scl == 0.0f || _orientation.scl == 2.0 * Math.PI)
            {
                // Frame has not yet rotated; apply one step of velocity
                _orientation = operationalAngularVelocity;
            }
            else
            {
                // Convert both quaternions to operational; combine; revert to valued
                operationalAngularVelocity.convertValuedToOperational();
                _orientation.convertValuedToOperational();
                _orientation = operationalAngularVelocity * _orientation;
                _orientation.convertOperationalToValued();
            }

            while (_orientation.scl > 2.0 * Math.PI)
            {
                _orientation.scl = _orientation.scl - 2.0f * (float)Math.PI;
            }
            while (_orientation.scl < 0.0)
            {
                _orientation.scl = _orientation.scl + 2.0f * (float)Math.PI;
            }
            _orientation.normalize();
        }
        public bool loadCube(float size)
        {
            // Loads vertices defining size x size x size tetrahedral, where size is the length of one side
            clear();
            size = size / 2.0f;

            // Set up each corner vertex
            aVertex vert0 = new aVertex(-size, size, size);
            aVertex vert1 = new aVertex(size, size, size);
            aVertex vert2 = new aVertex(size, -size, size);
            aVertex vert3 = new aVertex(-size, -size, size);
            aVertex vert4 = new aVertex(size, size, -size);
            aVertex vert5 = new aVertex(-size, size, -size);
            aVertex vert6 = new aVertex(-size, -size, -size);
            aVertex vert7 = new aVertex(size, -size, -size);

            // Create vertex arrays
            _numVertices = 36;
            _vertices.Add(vert0); _vertices.Add(vert2); _vertices.Add(vert1);     // Front face
            _vertices.Add(vert0); _vertices.Add(vert3); _vertices.Add(vert2);
            _vertices.Add(vert1); _vertices.Add(vert7); _vertices.Add(vert4);     // Right face
            _vertices.Add(vert1); _vertices.Add(vert2); _vertices.Add(vert7);
            _vertices.Add(vert4); _vertices.Add(vert6); _vertices.Add(vert5);     // Back face
            _vertices.Add(vert4); _vertices.Add(vert7); _vertices.Add(vert6);
            _vertices.Add(vert5); _vertices.Add(vert3); _vertices.Add(vert0);     // Left face
            _vertices.Add(vert5); _vertices.Add(vert6); _vertices.Add(vert3);
            _vertices.Add(vert0); _vertices.Add(vert4); _vertices.Add(vert5);     // Top face
            _vertices.Add(vert0); _vertices.Add(vert1); _vertices.Add(vert4);
            _vertices.Add(vert2); _vertices.Add(vert6); _vertices.Add(vert7);     // Bottom face
            _vertices.Add(vert2); _vertices.Add(vert3); _vertices.Add(vert6);

            refreshNormals();
            return(true);
        }
Example #6
0
        public aVertex norm()
        {
            aVertex toReturn = new aVertex();
            float   mag      = this.mag();

            toReturn.set(x / mag, y / mag, z / mag);
            return(toReturn);
        }
Example #7
0
 public aObject()
 {
     Mesh = new aMesh();
     Mesh.loadCube(1.0f);
     _location        = new aVertex();
     _orientation     = new kQuat();
     _color           = new aColor();
     _linearVelocity  = new aVertex();
     _angularVelocity = new kQuat();
 }
        public override void Update(float dt)
        {
            // Assume earth is at 0, 0, 0
            float   G      = 0.003f; // Correct gravitational contant for unit skew
            float   r      = _location.mag();
            float   gF     = G * _mass * _earthMass / (r * r);
            aVertex gForce = _location.norm() * -1.0f * gF;

            _linearVelocity += gForce * (dt / _mass);
            base.Update(dt);
        }
        public bool loadSphere(float size, int numFaces)
        {
            // Loads vertices defining sphere with radius size and the given number of faces
            clear();
            int   nPhi = (int)(Math.Sqrt(numFaces / 2.0f));
            int   nTht = nPhi * 2;
            float phi0, tht0, phi1, tht1;

            _numVertices = 6 * nPhi * nTht;

            // Create triangles by rotating about sphere
            for (int i = 0; i < nPhi; i++)
            {
                // Construct vertices for each latitude
                for (int j = 0; j < nTht; j++)
                {
                    // Redeclare to avoid reference crossover
                    aVertex vert0 = new aVertex();
                    aVertex vert1 = new aVertex();
                    aVertex vert2 = new aVertex();
                    aVertex vert3 = new aVertex();

                    // Construct vertices for each longitude, beginning with spherical coordinates
                    phi0 = (((float)i) / ((float)nPhi)) * (float)Math.PI;
                    phi1 = (((float)(i + 1)) / ((float)nPhi)) * (float)Math.PI;
                    tht0 = (((float)j) / ((float)nTht)) * 2 * (float)Math.PI;
                    tht1 = (((float)(j + 1)) / ((float)nTht)) * 2 * (float)Math.PI;

                    // Create vertices in cartesian from spherical coordinates
                    vert0.set(size * (float)Math.Sin(phi0) * (float)Math.Cos(tht0), size * (float)Math.Cos(phi0), -1 * size * (float)Math.Sin(phi0) * (float)Math.Sin(tht0));
                    vert1.set(size * (float)Math.Sin(phi1) * (float)Math.Cos(tht0), size * (float)Math.Cos(phi1), -1 * size * (float)Math.Sin(phi1) * (float)Math.Sin(tht0));
                    vert2.set(size * (float)Math.Sin(phi1) * (float)Math.Cos(tht1), size * (float)Math.Cos(phi1), -1 * size * (float)Math.Sin(phi1) * (float)Math.Sin(tht1));
                    vert3.set(size * (float)Math.Sin(phi0) * (float)Math.Cos(tht1), size * (float)Math.Cos(phi0), -1 * size * (float)Math.Sin(phi0) * (float)Math.Sin(tht1));

                    // Specify triangles
                    _vertices.Add(vert0); _vertices.Add(vert2); _vertices.Add(vert1);
                    _vertices.Add(vert0); _vertices.Add(vert3); _vertices.Add(vert2);
                    _texCoords.Add(new aTexCoord((float)(tht0 / (2.0f * Math.PI)), (float)(phi0 / Math.PI)));
                    _texCoords.Add(new aTexCoord((float)(tht1 / (2.0f * Math.PI)), (float)(phi1 / Math.PI)));
                    _texCoords.Add(new aTexCoord((float)(tht0 / (2.0f * Math.PI)), (float)(phi1 / Math.PI)));
                    _texCoords.Add(new aTexCoord((float)(tht0 / (2.0f * Math.PI)), (float)(phi0 / Math.PI)));
                    _texCoords.Add(new aTexCoord((float)(tht1 / (2.0f * Math.PI)), (float)(phi0 / Math.PI)));
                    _texCoords.Add(new aTexCoord((float)(tht1 / (2.0f * Math.PI)), (float)(phi1 / Math.PI)));
                }
            }
            refreshNormals();
            return(true);
        }
        public bool loadTetra(float size)
        {
            // Loads vertices defining size x size x size cube, where size is the length of one side.
            clear();
            float L = size / (float)Math.Sqrt(3.0f);
            float l = 2 * size / 3;

            // Set up each corner vertex
            aVertex vert0 = new aVertex(0.0f, l, 0.0f);
            aVertex vert1 = new aVertex(size / 2, -l / 2, -L / 2);
            aVertex vert2 = new aVertex(0.0f, -l / 2, L);
            aVertex vert3 = new aVertex(-size / 2, -l / 2, -L / 2);

            // Create vertex arrays
            _numVertices = 12;
            _vertices.Add(vert0); _vertices.Add(vert2); _vertices.Add(vert1);     // Right face
            _vertices.Add(vert0); _vertices.Add(vert1); _vertices.Add(vert3);     // Back face
            _vertices.Add(vert0); _vertices.Add(vert3); _vertices.Add(vert2);     // Left face
            _vertices.Add(vert1); _vertices.Add(vert2); _vertices.Add(vert3);     // Bottom face

            refreshNormals();
            return(true);
        }