Ejemplo n.º 1
0
        public TestSampleForm()
        {
            this.camera.Move( 0, 0, 50 );

            this.topVector = new Vector3F( 0, 0, 50 );
            //this.shader.Top = this.topVector;
            this.shader.Top = this.camera.Position;
            this.shader.Scale = 0.03f;

            this.shader.ApplyProgram( this.itemsManager );
            this.font.ApplyFont( this.itemsManager );
            this.texture.ApplyTexture( this.itemsManager );
            this.heightMap.ApplyTexture( this.itemsManager );

            this.RegisterPressed( Keys.Left, elapsed => this.shader.Top.X -= GetSpeedFactor() * elapsed );
            this.RegisterPressed( Keys.Right, elapsed => this.shader.Top.X += GetSpeedFactor() * elapsed );
            this.RegisterPressed( Keys.Down, elapsed => this.shader.Top.Y -= GetSpeedFactor() * elapsed );
            this.RegisterPressed( Keys.Up, elapsed => this.shader.Top.Y += GetSpeedFactor() * elapsed );
            this.RegisterPressed( Keys.PageUp, elapsed => this.shader.Top.Z -= GetSpeedFactor() * elapsed );
            this.RegisterPressed( Keys.PageDown, elapsed => this.shader.Top.Z += GetSpeedFactor() * elapsed );

            this.RegisterKeyDown( Keys.D1, () => this.quadIndexRotation = 0 );
            this.RegisterKeyDown( Keys.D2, () => this.quadIndexRotation = 1 );
            this.RegisterKeyDown( Keys.D3, () => this.quadIndexRotation = 2 );
            this.RegisterKeyDown( Keys.D4, () => this.quadIndexRotation = 3 );

            this.RegisterPressed( Keys.O, elapsed => this.shader.Bias -= elapsed * ScaleFactor );
            this.RegisterPressed( Keys.P, elapsed => this.shader.Bias += elapsed * ScaleFactor );

            this.RegisterPressed( Keys.K, elapsed => this.shader.Scale -= elapsed * ScaleFactor );
            this.RegisterPressed( Keys.L, elapsed => this.shader.Scale += elapsed * ScaleFactor );

            this.shader.TextureUnit = 0;
            this.shader.HeightMapUnit = 1;
        }
Ejemplo n.º 2
0
        public Sphere( float radius, int slices, int stacks )
        {
            this.radius = radius;
            this.slices = slices;
            this.stacks = stacks;

            this.vertices = new Vertex[(slices + 1) * (stacks + 1)];

            for (var slice = 0; slice <= slices; slice++)
            {
                var sliceAngle =  - slice * System.Math.PI / slices + System.Math.PI / 2;
                var x = (float)(radius * System.Math.Cos( sliceAngle ));
                var y = (float)(radius * System.Math.Sin( sliceAngle ));

                var sliceNormalX = -y / radius;
                var sliceNormalY = x / radius;

                for (var stack = 0; stack <= stacks; stack++)
                {
                    var stackAngle = 2 * stack * System.Math.PI / stacks;
                    var sx = (float)(x * System.Math.Cos( stackAngle ));
                    var sz = (float)(x * System.Math.Sin( stackAngle ));

                    var rotSliceNormalX = (float)(sliceNormalX * System.Math.Cos( stackAngle ));
                    var rotSliceNormalY = sliceNormalY;
                    var rotSliceNormalZ = (float)(sliceNormalX * System.Math.Sin( stackAngle ));

                    var nx = sx / radius;
                    var ny =  y / radius;
                    var nz = sz / radius;

                    var binormal = new Vector3F( rotSliceNormalX, rotSliceNormalY, rotSliceNormalZ );
                    var normal = new Vector3F( nx, ny, nz );
                    var tangent = normal ^ binormal;

                    this.vertices[this.GetIndex( slice, stack )] =
                        new Vertex( sx, y, sz, nx, ny, nz,
                                    rotSliceNormalX, rotSliceNormalY, rotSliceNormalZ,
                                    -tangent.X, -tangent.Y, -tangent.Z, (float)stack / stacks, 1.0f - (float)slice / slices );
                }
            }

            this.quadIndeces = new int[slices * (stacks + 1) * 4];

            for (var slice = 0; slice < slices; slice++)
            {
                for (var stack = 0; stack < stacks; stack++)
                {
                    this.quadIndeces[(this.GetIndex( slice, stack )) * 4 + 0] = this.GetIndex( slice + 0, stack + 0 );
                    this.quadIndeces[(this.GetIndex( slice, stack )) * 4 + 1] = this.GetIndex( slice + 0, stack + 1 );
                    this.quadIndeces[(this.GetIndex( slice, stack )) * 4 + 2] = this.GetIndex( slice + 1, stack + 1 );
                    this.quadIndeces[(this.GetIndex( slice, stack )) * 4 + 3] = this.GetIndex( slice + 1, stack + 0 );
                }
            }

            TangentVectorAttributeIndex = -1;
            BinormalVectorAttributeIndex = -1;
        }
Ejemplo n.º 3
0
 public void Set( Vector3F pos )
 {
     Set( pos.X, pos.Y, pos.Z );
 }
Ejemplo n.º 4
0
 public void SetPosition( Vector3F position )
 {
     SetPosition( position.X, position.Y, position.Z );
 }
Ejemplo n.º 5
0
 public static Matrix4F Translate( Vector3F position )
 {
     return Translate( position.X, position.Y, position.Z );
 }
Ejemplo n.º 6
0
 public Vertext( Vector3F position, Vector2F texCoord )
 {
     this.Position = position;
     this.TexCoord = texCoord;
 }