public void PopulateAsHollowCone(float radius, float height, LCC3Tessellation angleAndHeightDivs)
        {
            uint numAngularDivs = Math.Max(angleAndHeightDivs.X, 3);
            uint numHeightDivs = Math.Max(angleAndHeightDivs.Y, 1);

            float radiusHeightRatio = radius / height;
            float angularDivSpan = (float)(Math.PI * 2) / numAngularDivs;
            float heightDivSpan = height / numHeightDivs;
            float radialDivSpan = radius / numHeightDivs;
            float texAngularDivSpan = 1.0f / numAngularDivs;
            float texHeightDivSpan = 1.0f / numHeightDivs;

            uint vertexCount = (numAngularDivs + 1) * (numHeightDivs + 1);
            uint triangleCount = 2 * numAngularDivs * numHeightDivs - numAngularDivs;

            this.EnsureVertexContent();
            this.AllocatedVertexCapacity = vertexCount;
            this.AllocatedVertexIndexCapacity = (triangleCount * 3);

            uint vIdx = 0;
            uint iIdx = 0;

            for (uint ia = 0; ia <= numAngularDivs; ia++)
            {
                float angle = angularDivSpan * ia;
                float ca = (float)-Math.Cos(angle);
                float sa = (float)-Math.Sin(angle);

                LCC3Vector vtxNormal = new LCC3Vector(sa, radiusHeightRatio, ca).NormalizedVector();

                for (uint ih = 0; ih <= numHeightDivs; ih++, vIdx++)
                {
                    float vtxRadius = radius - (radialDivSpan * ih);
                    float vtxHt = heightDivSpan * ih;
                    LCC3Vector vtxLoc = new LCC3Vector(vtxRadius * sa, vtxHt, vtxRadius * ca);

                    this.SetVertexLocationAtIndex(vtxLoc,vIdx);
                    this.SetNormalAtIndex(vtxNormal, vIdx);

                    CCTex2F texCoord = new CCTex2F(texAngularDivSpan * ia, (1.0f - texHeightDivSpan * ih));
                    this.SetVertexTexCoord2FAtIndex(texCoord, vIdx);

                    if (ia < numAngularDivs && ih < numHeightDivs)
                    {
                        this.SetVertexIndexAtIndex( vIdx, iIdx++);
                        this.SetVertexIndexAtIndex((vIdx + numHeightDivs + 1),iIdx++);
                        this.SetVertexIndexAtIndex((vIdx + numHeightDivs + 2),iIdx++);

                        if (ih < numHeightDivs - 1)
                        {
                            this.SetVertexIndexAtIndex((vIdx + numHeightDivs + 2), iIdx++);
                            this.SetVertexIndexAtIndex((vIdx + 1), iIdx++);
                            this.SetVertexIndexAtIndex(vIdx, iIdx++);
                        }
                    }
                }
            }
        }
        public LCC3VertexLocations(int tag, string name)
            : base(tag, name)
        {
            _firstVertex = 0;
            _centerOfGeometry = LCC3Vector.CC3VectorZero;
            _boundingBox = LCC3BoundingBox.CC3BoundingBoxZero;
            _radius = 0.0f;

            this.MarkBoundaryDirty();
        }
        public LCC3NodeAnimationState(LCC3NodeAnimation animation, uint trackID, LCC3Node node)
        {
            _node = node;
            _animation = animation;
            _trackID = trackID;
            _blendingWeight = 1.0f;
            _animationTime = 0.0f;
            _location = LCC3Vector.CC3VectorZero;
            _quaternion = LCC3Quaternion.CC3QuaternionIdentity;
            _scale = LCC3Vector.CC3VectorUnitCube;
            _isEnabled = true;
            _isLocationAnimationEnabled = true;
            _isQuaternionAnimationEnabled = true;
            _isScaleAnimationEnabled = true;

            this.EstablishFrame(0.0f);
        }
Esempio n. 4
0
        public static LCC3Matrix4x4 CreateCameraViewMatrix(LCC3Vector cameraPosition, 
                                                           LCC3Vector cameraTarget,
                                                           CC3Quaternion cameraRotationRelativeToTarget,
                                                           LCC3Vector cameraUpDirection)
        {
            Vector3 xnaCameraPosAfterRotation
                = Vector3.Transform(cameraPosition.XnaVector - cameraTarget.XnaVector,
                                    cameraRotationRelativeToTarget.XnaQuaternion);

            xnaCameraPosAfterRotation += cameraTarget.XnaVector;

            Matrix xnaViewMatrix = Matrix.CreateLookAt(xnaCameraPosAfterRotation,
                                                       cameraTarget.XnaVector,
                                                       cameraUpDirection.XnaVector);

            return new LCC3Matrix4x4(xnaViewMatrix);
        }
Esempio n. 5
0
 private void UpdateGlobalLocation()
 {
     LCC3Vector4 locVec4 = new LCC3Vector4(_location, 0.0f);
     _globalLocation = _transformMatrix.TransformCC3Vector4(locVec4).TruncateToCC3Vector();
 }
        private void BuildBoundingBox()
        {
            LCC3Vector vl, vlMin, vlMax;
            vl = (this.VertexCount > 0) ? this.LocationAt(0) : LCC3Vector.CC3VectorZero;
            vlMin = vl;
            vlMax = vl;

            for (uint i = 1; i < this.VertexCount; i++)
            {
                vl = this.LocationAt(i);
                vlMin = LCC3Vector.CC3VectorMinimize(vlMin, vl);
                vlMax = LCC3Vector.CC3VectorMaximize(vlMax, vl);
            }

            _boundingBox = new LCC3BoundingBox(vlMin, vlMax);
            _centerOfGeometry = _boundingBox.Center;
            _boundaryIsDirty = false;
        }
        public void SetLocation(LCC3Vector location, uint index)
        {
            switch(this.ElementSize)
            {
                case 2:
                    _vertices[index] = new CCPoint(location.X, location.Y);
                    break;
                case 4:
                    _vertices[index] = new LCC3Vector4(location, 1.0f);
                    break;
                default:
                    _vertices[index] = location;
                    break;
            }

            this.MarkBoundaryDirty();
        }
        public void PopulateFrom(LCC3VertexLocations another)
        {
            base.PopulateFrom(another);

            _firstVertex = another._firstVertex;
            _boundingBox = another.BoundingBox;
            _centerOfGeometry = another.CenterOfGeometry;
            _radius = another.Radius;
            _boundaryIsDirty = another.BoundaryIsDirty;
            _radiusIsDirty = another.RadiusIsDirty;
        }
Esempio n. 9
0
 public void SetBitangentAtIndex(LCC3Vector bitangent, uint index)
 {
     _vertexBitangents.SetTangentAtIndex(bitangent, index);
 }
Esempio n. 10
0
        public void DrawTextureTest()
        {
            _progPipeline.SetClearColor(new CCColor4F(0.2f, 0.5f, 0.8f, 1.0f));
            _progPipeline.SetClearDepth(100.0f);
            _progPipeline.ClearBuffers(LCC3BufferMask.ColorBuffer | LCC3BufferMask.DepthBuffer);

            _progPipeline.EnableBlend(false);
            _progPipeline.EnableDepthTest(true);
            _progPipeline.SetDepthMask(true);
            _progPipeline.SetDepthFunc(LCC3DepthStencilFuncMode.LessOrEqual);
            _progPipeline.EnableCullFace(true);

            _progPipeline.CurrentlyActiveShader = _tankShader;

            foreach (ModelMesh mesh in _tankModel.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {

                    LCC3ShaderUniform worldViewProjUniform = _tankShader.UniformNamed("WorldViewProj");
                    LCC3Matrix4x4 worldViewProjMatrix
                        = new LCC3Matrix4x4(_tankTransforms[mesh.ParentBone.Index] * _graphicsContext.ViewMatrix.XnaMatrix * _graphicsContext.ProjectionMatrix.XnaMatrix);
                    worldViewProjUniform.SetValue(worldViewProjMatrix);
                    worldViewProjUniform.UpdateShaderValue();

                    LCC3ShaderUniform eyePositionUniform = _tankShader.UniformNamed("EyePosition");
                    LCC3Vector eyePosition = new LCC3Vector(Matrix.Invert(_graphicsContext.ViewMatrix.XnaMatrix).Translation);
                    eyePositionUniform.SetValue(eyePosition);
                    eyePositionUniform.UpdateShaderValue();

                    LCC3ShaderUniform worldUniform = _tankShader.UniformNamed("World");
                    LCC3Matrix4x4 worldMatrix = new LCC3Matrix4x4(_tankTransforms[mesh.ParentBone.Index]);
                    worldUniform.SetValue(worldMatrix);
                    worldUniform.UpdateShaderValue();

                    LCC3ShaderUniform worldInvTransUniform = _tankShader.UniformNamed("WorldInverseTranspose");
                    LCC3Matrix4x4 worldInvTransMatrix = new LCC3Matrix4x4(Matrix.Invert(Matrix.Transpose(_tankTransforms[mesh.ParentBone.Index])));
                    worldInvTransUniform.SetValue(worldInvTransMatrix);
                    worldInvTransUniform.UpdateShaderValue();

                    _progPipeline.XnaVertexBuffer = part.VertexBuffer;
                    _progPipeline.XnaIndexBuffer = part.IndexBuffer;

                    //_progPipeline.DrawIndices(LCC3DrawMode.TriangleList, part.VertexOffset, 0, part.NumVertices, part.StartIndex, part.PrimitiveCount);
                }
            }
        }
Esempio n. 11
0
 private LCC3Face(LCC3Vector v)
     : this(v,v,v)
 {
 }
Esempio n. 12
0
        public static LCC3Matrix4x4 CreateWorldMatrix(LCC3Vector worldPosition, 
                                                      LCC3Vector worldScale,
                                                      CC3Quaternion localRotation,
                                                      CC3Quaternion rotationRelativeToAnchor,
                                                      LCC3Vector anchorPointRelativeToPosition)
        {
            Matrix xnaTranslationMatrix = Matrix.CreateTranslation(worldPosition.XnaVector);
            Matrix xnaScaleMatrix = Matrix.CreateScale(worldScale.XnaVector);
            Matrix xnaLocalRotationMatrix = Matrix.CreateFromQuaternion(localRotation.XnaQuaternion);
            Matrix xnaRotationRelativeToAnchorMatrix = Matrix.CreateFromQuaternion(rotationRelativeToAnchor.XnaQuaternion);
            Matrix xnaRotationAnchorTranslationMatrix = Matrix.CreateTranslation(anchorPointRelativeToPosition.XnaVector);

            return new LCC3Matrix4x4(xnaTranslationMatrix *
                                     Matrix.Invert(xnaRotationAnchorTranslationMatrix) *
                                     xnaRotationRelativeToAnchorMatrix *
                                     xnaRotationAnchorTranslationMatrix *
                                     xnaLocalRotationMatrix *
                                     xnaScaleMatrix);
        }
Esempio n. 13
0
 public void SetNormalAtIndex(LCC3Vector normal, uint index)
 {
     _vertexNormals.SetNormalAtIndex(normal, index);
 }
Esempio n. 14
0
        public void PopulateAsSphere(float radius, LCC3Tessellation divsPerAxis)
        {
            divsPerAxis.X = Math.Max(divsPerAxis.X, 3);
            divsPerAxis.Y = Math.Max(divsPerAxis.Y, 2);

            CCSize divSpan = new CCSize((float)((Math.PI * 2) / divsPerAxis.X), (float)(Math.PI / divsPerAxis.Y));
            CCSize divTexSpan = new CCSize((float)(1.0 / divsPerAxis.X), (float)(1.0 / divsPerAxis.Y));
            float halfDivTexSpanWidth = divTexSpan.Width * 0.5f;

            LCC3Tessellation verticesPerAxis = new LCC3Tessellation(0,0);
            verticesPerAxis.X = divsPerAxis.X + 1;
            verticesPerAxis.Y = divsPerAxis.Y + 1;
            uint vertexCount = verticesPerAxis.X * verticesPerAxis.Y;
            uint triangleCount = divsPerAxis.X * (divsPerAxis.Y - 1) * 2;

            this.EnsureVertexContent();
            this.AllocatedVertexCapacity = vertexCount;
            this.AllocatedVertexIndexCapacity = (triangleCount * 3);
            LCC3VertexIndices indices = this.VertexIndices;

            uint vIndx = 0;
            uint iIndx = 0;

            for (uint iy = 0; iy < verticesPerAxis.Y; iy++)
            {
                float y = divSpan.Height * iy;
                float sy = (float)Math.Sin(y);
                float cy = (float)Math.Cos(y);

                for (uint ix = 0; ix < verticesPerAxis.X; ix++)
                {
                    float x = divSpan.Width * ix;
                    float sx = (float)Math.Sin(x);
                    float cx = (float)Math.Cos(x);

                    LCC3Vector unitRadial = new LCC3Vector(-(sy * sx), cy, -(sy * cx));
                    this.SetVertexLocationAtIndex(unitRadial * radius, vIndx);

                    this.SetNormalAtIndex(unitRadial.NormalizedVector(), vIndx);

                    float uOffset = 0.0f;
                    if (iy == 0)
                    {
                        uOffset = halfDivTexSpanWidth;
                    }

                    if (iy == (verticesPerAxis.Y - 1))
                    {
                        uOffset = -halfDivTexSpanWidth;
                    }

                    float u = divTexSpan.Width * ix + uOffset;
                    float v = divTexSpan.Height * iy;
                    this.SetVertexTexCoord2FAtIndex(new CCTex2F(u, v), vIndx);

                    if (iy > 0 && ix > 0)
                    {
                        if (iy > 1)
                        {
                            indices.SetIndex(vIndx, iIndx++);
                            indices.SetIndex(vIndx - verticesPerAxis.X, iIndx++);
                            indices.SetIndex(vIndx - verticesPerAxis.Y - 1, iIndx++);
                        }

                        if (iy < (verticesPerAxis.Y - 1))
                        {
                            indices.SetIndex(vIndx - verticesPerAxis.X - 1, iIndx++);
                            indices.SetIndex(vIndx - 1, iIndx++);
                            indices.SetIndex(vIndx, iIndx++);
                        }
                    }

                    vIndx++;
                }
            }
        }
Esempio n. 15
0
 public void SetNormalAtIndex(LCC3Vector aNormal, uint index)
 {
     _vertices[(int)index] = aNormal;
 }
Esempio n. 16
0
 public void SetVertexLocationAtIndex(LCC3Vector location, uint index)
 {
     _vertexLocations.SetLocation(location, index);
 }
Esempio n. 17
0
 public void SetTangentAtIndex(LCC3Vector tangent, uint index)
 {
     _vertexTangents.SetTangentAtIndex(tangent, index);
 }
Esempio n. 18
0
        public static LCC3Matrix4x4 CreateTranslationMatrix(LCC3Vector worldTranslation)
        {
            Matrix xnaTranslationMatrix = Matrix.CreateTranslation(worldTranslation.XnaVector);

            return new LCC3Matrix4x4(xnaTranslationMatrix);
        }
Esempio n. 19
0
 public void SetTangentAtIndex(LCC3Vector aTangent, uint index)
 {
     _vertices[(int)index] = aTangent;
 }
Esempio n. 20
0
 public LCC3Face(LCC3Vector v1, LCC3Vector v2, LCC3Vector v3)
 {
     _vertex1 = v1;
     _vertex2 = v2;
     _vertex3 = v3;
 }
Esempio n. 21
0
        public LCC3Vector LocationAt(uint index)
        {
            LCC3Vector location = (LCC3Vector)_vertices[(int)index];

            switch(this.ElementSize)
            {
                case 2:
                    location = new LCC3Vector(location.X, location.Y, 0.0f);
                    break;
            }

            return location;
        }
Esempio n. 22
0
        private void InitializeTankEffect()
        {
            _tankShader = new LCC3ShaderProgram(0, "MyShader", this, "Content/BasicEffect.ogl.mgfxo");
            _tankTexture = new LCC3GraphicsTexture2D("turret_alt_diff_tex_0");
            _tankShader.XnaShaderEffect.CurrentTechnique = _tankShader.XnaShaderEffect.Techniques[21]; //5

            LCC3ShaderUniform textureUniform = _tankShader.UniformNamed("Texture");
            textureUniform.SetValue(_tankTexture);
            textureUniform.UpdateShaderValue();

            LCC3ShaderUniform diffuseColorUniform = _tankShader.UniformNamed("DiffuseColor");
            LCC3Vector4 diffuseColor = new LCC3Vector4(1.0f, 1.0f, 1.0f, 0.4f);
            diffuseColorUniform.SetValue(diffuseColor);
            diffuseColorUniform.UpdateShaderValue();

            LCC3ShaderUniform emissiveColorUniform = _tankShader.UniformNamed("EmissiveColor");
            LCC3Vector emissiveColor = new LCC3Vector(0.5f, 0.5f, 0.9f);
            emissiveColorUniform.SetValue(emissiveColor);
            emissiveColorUniform.UpdateShaderValue();

            LCC3ShaderUniform specularColorUniform = _tankShader.UniformNamed("SpecularColor");
            LCC3Vector specularColor = new LCC3Vector(1.0f, 0.0f, 0.0f);
            specularColorUniform.SetValue(specularColor);
            specularColorUniform.UpdateShaderValue();

            LCC3ShaderUniform specularPowerUniform = _tankShader.UniformNamed("SpecularPower");
            float specularPower = 100.0f;
            specularPowerUniform.SetValue(specularPower);
            specularPowerUniform.UpdateShaderValue();

            LCC3ShaderUniform light0DirectionUniform = _tankShader.UniformNamed("DirLight0Direction");
            LCC3Vector light0Direction = (new LCC3Vector(-0.5f, -1.2f, -1.0f)).NormalizedVector();
            light0DirectionUniform.SetValue(light0Direction);
            light0DirectionUniform.UpdateShaderValue();

            LCC3ShaderUniform light0DiffuseColorUniform = _tankShader.UniformNamed("DirLight0DiffuseColor");
            LCC3Vector light0DiffuseColor = new LCC3Vector(1.0f, 2.0f, 2.0f);
            light0DiffuseColorUniform.SetValue(light0DiffuseColor);
            light0DiffuseColorUniform.UpdateShaderValue();

            LCC3ShaderUniform light0SpecularColorUniform = _tankShader.UniformNamed("DirLight0SpecularColor");
            LCC3Vector light0SpecularColor = new LCC3Vector(1.0f, 0.0f, 0.0f);
            light0SpecularColorUniform.SetValue(light0SpecularColor);
            light0DiffuseColorUniform.UpdateShaderValue();
        }
Esempio n. 23
0
        public void MoveMeshOriginTo(LCC3Vector location)
        {
            for (uint i = 0; i < this.VertexCount; i++)
            {
                LCC3Vector locOld = this.LocationAt(i);
                LCC3Vector locNew = locOld - location;
                this.SetLocation(locNew, i);
            }

            this.MarkBoundaryDirty();
            this.UpdateGraphicsBuffer();
        }
Esempio n. 24
0
        public void PopulateFrom(LCC3Texture texture)
        {
            base.PopulateFrom(texture);

            _graphicsTexture = texture.GraphicsTexture;
            _lightDirection = texture.LightDirection;
            _isBumpMap = texture.IsBumpMap;
        }
Esempio n. 25
0
 public void MoveMeshOriginTo(LCC3Vector location)
 {
     _vertexLocations.MoveMeshOriginTo(location);
 }