Пример #1
0
        public void ColorRGBAF_CastToVertex4()
        {
            float r = (float)NextComponent(1.0f);
            float g = (float)NextComponent(1.0f);
            float b = (float)NextComponent(1.0f);
            float a = (float)NextComponent(1.0f);

            ColorRGBAF v      = new ColorRGBAF(r, g, b, a);
            Vertex4f   vArray = v;

            Assert.AreEqual(r, vArray.x);
            Assert.AreEqual(g, vArray.y);
            Assert.AreEqual(b, vArray.z);
            Assert.AreEqual(a, vArray.w);
        }
Пример #2
0
        public Vertex4()
        {
            Random random = new Random();

            _MinArray = new Vertex4f[MinArraySize];
            for (int i = 0; i < _MinArray.Length; i++)
            {
                _MinArray[i] = new Vertex4f((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), Math.Max(0.1f, (float)random.NextDouble()));
            }

            _MaxArray = new Vertex4f[MaxArraySize];
            for (int i = 0; i < _MaxArray.Length; i++)
            {
                _MaxArray[i] = new Vertex4f((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), Math.Max(0.1f, (float)random.NextDouble()));
            }
        }
Пример #3
0
        /// <summary>
        /// Compute the product between Matrix4x4 and Vertex4f.
        /// </summary>
        /// <param name="m">
        /// A <see cref="Matrix4x4"/> that specify the left multiplication operand.
        /// </param>
        /// <param name="v">
        /// A <see cref="Vertex4f"/> that specify the right multiplication operand.
        /// </param>
        protected static Vertex4f ComputeMatrixProduct(Matrix4x4 m, Vertex4f v)
        {
            float x, y, z, w;

            unsafe
            {
                fixed(float *pm = m.MatrixBuffer)
                {
                    x = pm[0x0] * v.x + pm[0x4] * v.y + pm[0x8] * v.z + pm[0xC] * v.w;
                    y = pm[0x1] * v.x + pm[0x5] * v.y + pm[0x9] * v.z + pm[0xD] * v.w;
                    z = pm[0x2] * v.x + pm[0x6] * v.y + pm[0xA] * v.z + pm[0xE] * v.w;
                    w = pm[0x3] * v.x + pm[0x7] * v.y + pm[0xB] * v.z + pm[0xF] * v.w;
                }
            }

            return(new Vertex4f(x, y, z, w));
        }
Пример #4
0
        /// <summary>
        /// Automatically computes bounding box for the specified vertex arrays.
        /// </summary>
        /// <param name="vertexArrayObject">
        ///
        /// </param>
        /// <returns>
        /// It returns the <see cref="IBoundingVolume"/> for <paramref name="vertexArrayObject"/>, if possible.
        /// </returns>
        private static IBoundingVolume ComputeBoundingVolume(VertexArrays vertexArrayObject)
        {
            if (vertexArrayObject == null)
            {
                throw new ArgumentNullException("vertexArrayObject");
            }

            VertexArrays.IVertexArray vertexArray = vertexArrayObject.GetVertexArray(VertexArraySemantic.Position);
            if (vertexArray == null)
            {
                return(null);
            }

            ArrayBufferBase positionArray     = vertexArray.Array;
            Type            positionArrayType = positionArray.GetType();

            if (positionArrayType == typeof(ArrayBuffer <Vertex4f>))
            {
                ArrayBuffer <Vertex4f> positionArray4f = (ArrayBuffer <Vertex4f>)positionArray;
                Vertex4f min = Vertex4f.Maximum, max = Vertex4f.Minimum;
                positionArray4f.MinMax(out min, out max);

                return(new BoundingBox((Vertex3f)min, (Vertex3f)max));
            }
            else if (positionArrayType == typeof(ArrayBuffer <Vertex3f>))
            {
                ArrayBuffer <Vertex3f> positionArray3f = (ArrayBuffer <Vertex3f>)positionArray;
                Vertex3f min = Vertex3f.Maximum, max = Vertex3f.Minimum;
                positionArray3f.MinMax(out min, out max);

                return(new BoundingBox(min, max));
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
            public VertexArrays CreateArrays(ObjContext objContext)
            {
                if (objContext == null)
                {
                    throw new ArgumentNullException("objContext");
                }

                VertexArrays        vertexArray = new VertexArrays();
                List <ObjFaceCoord> coords      = new List <ObjFaceCoord>();
                bool hasTexCoord = Material.DiffuseTexture != null;
                bool hasNormals  = false;
                bool hasTanCoord = hasTexCoord && Material.NormalTexture != null;

                foreach (ObjFace f in Faces)
                {
                    hasTexCoord |= f.HasTexCoord;
                    hasNormals  |= f.HasNormal;
                    coords.AddRange(f.Triangulate());
                }

                uint vertexCount = (uint)coords.Count;

                Vertex4f[] position = new Vertex4f[vertexCount];
                Vertex3f[] normal   = hasNormals ? new Vertex3f[vertexCount] : null;
                Vertex2f[] texcoord = new Vertex2f[vertexCount];

                for (int i = 0; i < position.Length; i++)
                {
                    Debug.Assert(coords[i].VertexIndex < objContext.Vertices.Count);
                    position[i] = objContext.Vertices[coords[i].VertexIndex];

                    if (hasTexCoord)
                    {
                        Debug.Assert(coords[i].TexCoordIndex < objContext.TextureCoords.Count);
                        texcoord[i] = objContext.TextureCoords[coords[i].TexCoordIndex];
                    }

                    if (hasNormals)
                    {
                        Debug.Assert(coords[i].NormalIndex < objContext.Normals.Count);
                        normal[i] = objContext.Normals[coords[i].NormalIndex];
                    }
                }

                // Position (mandatory)
                ArrayBuffer <Vertex4f> positionBuffer = new ArrayBuffer <Vertex4f>();

                positionBuffer.Create(position);
                vertexArray.SetArray(positionBuffer, VertexArraySemantic.Position);

                // Layout (triangles)
                vertexArray.SetElementArray(PrimitiveType.Triangles);

                // Texture
                if (hasTexCoord)
                {
                    ArrayBuffer <Vertex2f> texCoordBuffer = new ArrayBuffer <Vertex2f>();
                    texCoordBuffer.Create(texcoord);
                    vertexArray.SetArray(texCoordBuffer, VertexArraySemantic.TexCoord);
                }

                // Normals
                if (hasNormals)
                {
                    ArrayBuffer <Vertex3f> normalBuffer = new ArrayBuffer <Vertex3f>();
                    normalBuffer.Create(normal);
                    vertexArray.SetArray(normalBuffer, VertexArraySemantic.Normal);
                }
                else
                {
                    ArrayBuffer <Vertex3f> normalBuffer = new ArrayBuffer <Vertex3f>();
                    normalBuffer.Create(vertexCount);
                    vertexArray.SetArray(normalBuffer, VertexArraySemantic.Normal);
                    // XXX vertexArray.GenerateNormals();
                }

                // Tangents
                if (hasTanCoord)
                {
                    ArrayBuffer <Vertex3f> tanCoordBuffer = new ArrayBuffer <Vertex3f>();
                    tanCoordBuffer.Create(vertexCount);
                    vertexArray.SetArray(tanCoordBuffer, VertexArraySemantic.Tangent);

                    ArrayBuffer <Vertex3f> bitanCoordBuffer = new ArrayBuffer <Vertex3f>();
                    bitanCoordBuffer.Create(vertexCount);
                    vertexArray.SetArray(bitanCoordBuffer, VertexArraySemantic.Bitangent);

                    // XXX vertexArray.GenerateTangents();
                }

                return(vertexArray);
            }
Пример #6
0
 protected void LoadVector4(int location, Vertex4f value)
 {
     Gl.Uniform4f(location, 1, value);
 }
Пример #7
0
 public void LoadClipPlane(Vertex4f plane)
 {
     base.LoadVector4(this.location_waterClippingPlane, plane);
 }
 /// <summary>
 /// Set uniform state variable (variant type variable)
 /// </summary>
 /// <param name="ctx">
 /// A <see cref="GraphicsContext"/> used for operations.
 /// </param>
 /// <param name="uniformName">
 /// A <see cref="String"/> that specify the variable name in the shader source.
 /// </param>
 /// <param name="v">
 /// A <see cref="Vertex3f"/> holding the uniform variabile data.
 /// </param>
 public void SetVariantUniform(GraphicsContext ctx, string uniformName, Vertex4f v)
 {
     SetVariantUniform(ctx, uniformName, v.x, v.y, v.z, v.w);
 }
Пример #9
0
        private Vertex3f ToWorldCoords(Vertex4f eyeCoords)
        {
            Vertex4f rayWorld = viewMatrix.Inverse * eyeCoords;

            return(new Vertex3f(rayWorld.x, rayWorld.y, rayWorld.z).Normalized);//z 구성 요소에 -1을 수동으로 지정 했으므로 광선이 정규화되지 않았기때문에 정규화 필요.
        }
Пример #10
0
        private Vertex4f ToEyeCoords(Vertex4f clipCoords)
        {
            Vertex4f eyeCoords = projectionMatrix.Inverse * clipCoords;

            return(new Vertex4f(eyeCoords.x, eyeCoords.y, -1f, 0f));// z, w 부분을 ​"지점이 아닌 앞으로"를 의미 하도록 수동으로 설정
        }
Пример #11
0
 /// <summary>
 /// Construct a Matrix3x4f specifying the matrix columns.
 /// </summary>
 public Matrix3x4f(Vertex4f c0, Vertex4f c1, Vertex4f c2)
 {
     Column0 = c0;
     Column1 = c1;
     Column2 = c2;
 }
Пример #12
0
 /// <summary>
 /// Construct a Matrix2x4f specifying the matrix columns.
 /// </summary>
 public Matrix2x4f(Vertex4f c0, Vertex4f c1)
 {
     Column0 = c0;
     Column1 = c1;
 }
		/// <summary>
		/// Set uniform state variable (variant type variable)
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> used for operations.
		/// </param>
		/// <param name="uniformName">
		/// A <see cref="String"/> that specify the variable name in the shader source.
		/// </param>
		/// <param name="v">
		/// A <see cref="Vertex3f"/> holding the uniform variabile data.
		/// </param>
		public void SetVariantUniform(GraphicsContext ctx, string uniformName, Vertex4f v)
		{
			SetVariantUniform(ctx, uniformName, v.x, v.y, v.z, v.w);
		}
Пример #14
0
 void IShaderUniformContainer.SetUniform(GraphicsContext ctx, string uniformName, Vertex4f v)
 {
     SetUniform(uniformName, v);
 }
Пример #15
0
 /// <summary>
 /// Creates a normalized plane.
 /// </summary>
 /// <param name="a">
 /// A <see cref="Vertex4f"/> that specify the plane components.
 /// </param>
 /// <returns>
 /// It returns the normalized plane.
 /// </returns>
 private static Planef NormalizePlane(Vertex4f v)
 {
     return(NormalizePlane(v.x, v.y, v.z, v.w));
 }
Пример #16
0
        private void Render(int width, int height, List <Light> lightList, Camera camera, Vertex4f clipPlane, float frameTimeSec)
        {
            Prepare(width, height);

            //Entities
            this.entityShader.Start();
            this.entityShader.LoadClipPlane(clipPlane);
            this.entityShader.LoadSkyColor(SKY_COLOR_RED, SKY_COLOR_GREEN, SKY_COLOR_BLUE);
            this.entityShader.LoadLights(lightList);
            this.entityShader.LoadViewMatrix(camera);
            this.entityRenderer.Render(this.entities);
            this.entityShader.Stop();

            //Terrain
            this.terrainShader.Start();
            this.terrainShader.LoadClipPlane(clipPlane);
            this.terrainShader.LoadSkyColor(SKY_COLOR_RED, SKY_COLOR_GREEN, SKY_COLOR_BLUE);
            this.terrainShader.LoadLights(lightList);
            this.terrainShader.LoadViewMatrix(camera);
            this.terrainShader.LoadLightViewMatrix(this.shadowRenderer.LightSpaceMatrix);
            this.terrainRenderer.Render(this.terrainList);
            this.terrainShader.Stop();

            //Skybox
            this.skyboxRenderer.Render(camera, new Vertex3f(SKY_COLOR_RED, SKY_COLOR_GREEN, SKY_COLOR_BLUE), frameTimeSec);
        }
Пример #17
0
 public void RenderScene(int width, int height, List <Light> lights, Camera camera, Vertex4f clipPlane, float frameTimeSec)
 {
     Render(width, height, lights, camera, clipPlane, frameTimeSec);
 }