示例#1
0
int SkySphere::Generate(void *last, int argc, char **argv, char **azColName){
    float phi, theta, r;
    sscanf(argv[7], "%f", &theta);
    sscanf(argv[8], "%f", &phi);
    sscanf(argv[9], "%f", &r);
    r*=10;

    phi+=180;

    int i = *reinterpret_cast<int*>(last);
    m->Verteces[i+0] = VertexPositionNormalTexture(vec3(), SphToDec(phi, theta, r), vec2(0,0));
    m->Verteces[i+1] = VertexPositionNormalTexture(vec3(), SphToDec(phi+0.01f, theta, r), vec2(1,0));
    m->Verteces[i+2] = VertexPositionNormalTexture(vec3(), SphToDec(phi, theta+0.01f, r), vec2(0,1));
    m->Indeces[i+0] = i+0;
    m->Indeces[i+1] = i+1;
    m->Indeces[i+2] = i+2;
    return 0;
}
示例#2
0
        /// <summary>
        /// Creates a <see cref="VertexBuffer"/> filled with <see cref="VertexPositionNormalTexture"/> vertices forming a box.
        /// </summary>
        /// <remarks>Always draw using a non-indexed TriangleList of 12 primitives.</remarks>
        /// <param name="device">The <see cref="GraphicsDevice"/> that is associated with the created box.</param>
        /// <param name="width">Width of the box, along the x-axis.</param>
        /// <param name="height">Height of the box, along the y-axis.</param>
        /// <param name="depth">Depth of the box, along the z-axis.</param>
        void Shape3D::CreateTexturedBox(float width, float height, float depth, const char* aShaderName)
        {
            

            // Because the box is centered at the origin, need to divide by two to find the + and - offsets
            width = width / 2.0f;
            height = height / 2.0f;
            depth = depth / 2.0f;

            VertexPositionNormalTexture cubeVertices[36];

            D3DXFROMWINEVECTOR3 topLeftFront = D3DXFROMWINEVECTOR3(-width, height, depth);
            D3DXFROMWINEVECTOR3 bottomLeftFront = D3DXFROMWINEVECTOR3(-width, -height, depth);
            D3DXFROMWINEVECTOR3 topRightFront = D3DXFROMWINEVECTOR3(width, height, depth);
            D3DXFROMWINEVECTOR3 bottomRightFront = D3DXFROMWINEVECTOR3(width, -height, depth);
            D3DXFROMWINEVECTOR3 topLeftBack = D3DXFROMWINEVECTOR3(-width, height, -depth);
            D3DXFROMWINEVECTOR3 topRightBack = D3DXFROMWINEVECTOR3(width, height, -depth);
            D3DXFROMWINEVECTOR3 bottomLeftBack = D3DXFROMWINEVECTOR3(-width, -height, -depth);
            D3DXFROMWINEVECTOR3 bottomRightBack = D3DXFROMWINEVECTOR3(width, -height, -depth);

            D3DXFROMWINEVECTOR2 textureTopLeft = D3DXFROMWINEVECTOR2(0.0f, 0.0f);
            D3DXFROMWINEVECTOR2 textureTopRight = D3DXFROMWINEVECTOR2(1.0f, 0.0f);
            D3DXFROMWINEVECTOR2 textureBottomLeft = D3DXFROMWINEVECTOR2(0.0f, 1.0f);
            D3DXFROMWINEVECTOR2 textureBottomRight = D3DXFROMWINEVECTOR2(1.0f, 1.0f);

            D3DXFROMWINEVECTOR3 frontNormal = D3DXFROMWINEVECTOR3(0.0f, 0.0f, 1.0f);
            D3DXFROMWINEVECTOR3 backNormal = D3DXFROMWINEVECTOR3(0.0f, 0.0f, -1.0f);
            D3DXFROMWINEVECTOR3 topNormal = D3DXFROMWINEVECTOR3(0.0f, 1.0f, 0.0f);
            D3DXFROMWINEVECTOR3 bottomNormal = D3DXFROMWINEVECTOR3(0.0f, -1.0f, 0.0f);
            D3DXFROMWINEVECTOR3 leftNormal = D3DXFROMWINEVECTOR3(-1.0f, 0.0f, 0.0f);
            D3DXFROMWINEVECTOR3 rightNormal = D3DXFROMWINEVECTOR3(1.0f, 0.0f, 0.0f);

            // Front face.
            cubeVertices[1] = VertexPositionNormalTexture(topLeftFront, frontNormal, textureTopLeft);
            cubeVertices[0] = VertexPositionNormalTexture(bottomLeftFront, frontNormal, textureBottomLeft);
            cubeVertices[2] = VertexPositionNormalTexture(topRightFront, frontNormal, textureTopRight);
            cubeVertices[4] = VertexPositionNormalTexture(bottomLeftFront, frontNormal, textureBottomLeft);
            cubeVertices[3] = VertexPositionNormalTexture(bottomRightFront, frontNormal, textureBottomRight);
            cubeVertices[5] = VertexPositionNormalTexture(topRightFront, frontNormal, textureTopRight);

            // Back face.
            cubeVertices[7] = VertexPositionNormalTexture(topLeftBack, backNormal, textureTopRight);
            cubeVertices[6] = VertexPositionNormalTexture(topRightBack, backNormal, textureTopLeft);
            cubeVertices[8] = VertexPositionNormalTexture(bottomLeftBack, backNormal, textureBottomRight);
            cubeVertices[10] = VertexPositionNormalTexture(bottomLeftBack, backNormal, textureBottomRight);
            cubeVertices[9] = VertexPositionNormalTexture(topRightBack, backNormal, textureTopLeft);
            cubeVertices[11] = VertexPositionNormalTexture(bottomRightBack, backNormal, textureBottomLeft);

            // Top face.
            cubeVertices[13] = VertexPositionNormalTexture(topLeftFront, topNormal, textureBottomLeft);
            cubeVertices[12] = VertexPositionNormalTexture(topRightBack, topNormal, textureTopRight);
            cubeVertices[14] = VertexPositionNormalTexture(topLeftBack, topNormal, textureTopLeft);
            cubeVertices[16] = VertexPositionNormalTexture(topLeftFront, topNormal, textureBottomLeft);
            cubeVertices[15] = VertexPositionNormalTexture(topRightFront, topNormal, textureBottomRight);
            cubeVertices[17] = VertexPositionNormalTexture(topRightBack, topNormal, textureTopRight);

            // Bottom face.
            cubeVertices[19] = VertexPositionNormalTexture(bottomLeftFront, bottomNormal, textureTopLeft);
            cubeVertices[18] = VertexPositionNormalTexture(bottomLeftBack, bottomNormal, textureBottomLeft);
            cubeVertices[20] = VertexPositionNormalTexture(bottomRightBack, bottomNormal, textureBottomRight);
            cubeVertices[22] = VertexPositionNormalTexture(bottomLeftFront, bottomNormal, textureTopLeft);
            cubeVertices[21] = VertexPositionNormalTexture(bottomRightBack, bottomNormal, textureBottomRight);
            cubeVertices[23] = VertexPositionNormalTexture(bottomRightFront, bottomNormal, textureTopRight);

            // Left face.
            cubeVertices[25] = VertexPositionNormalTexture(topLeftFront, leftNormal, textureTopRight);
            cubeVertices[24] = VertexPositionNormalTexture(bottomLeftBack, leftNormal, textureBottomLeft);
            cubeVertices[26] = VertexPositionNormalTexture(bottomLeftFront, leftNormal, textureBottomRight);
            cubeVertices[28] = VertexPositionNormalTexture(topLeftBack, leftNormal, textureTopLeft);
            cubeVertices[27] = VertexPositionNormalTexture(bottomLeftBack, leftNormal, textureBottomLeft);
            cubeVertices[29] = VertexPositionNormalTexture(topLeftFront, leftNormal, textureTopRight);

            // Right face.
            cubeVertices[31] = VertexPositionNormalTexture(topRightFront, rightNormal, textureTopLeft);
            cubeVertices[30] = VertexPositionNormalTexture(bottomRightFront, rightNormal, textureBottomLeft);
            cubeVertices[32] = VertexPositionNormalTexture(bottomRightBack, rightNormal, textureBottomRight);
            cubeVertices[34] = VertexPositionNormalTexture(topRightBack, rightNormal, textureTopRight);
            cubeVertices[33] = VertexPositionNormalTexture(topRightFront, rightNormal, textureTopLeft);
            cubeVertices[35] = VertexPositionNormalTexture(bottomRightBack, rightNormal, textureBottomRight);

            // Create the actual vertex buffer
	    VertexBuffer=IRenderer::GetRendererInstance()->addVertexBuffer(VertexPositionNormalTexture::VertexSizeInBytes * 36, STATIC, cubeVertices);

            VertexCount = 36;
            TriangleCount = 12;

	Shader = FW3ShadersFactory::GetShader(aShaderName, "main", "main");
	VertexDeclaration = FW3ShadersFactory::GetVertexFormat(eTexturedBox, Shader);

            VertexSizeInBytes = VertexPositionNormalTexture::VertexSizeInBytes;

            SamplerStateID ss=IRenderer::GetRendererInstance()->Getlinear();
		texID=IRenderer::GetRendererInstance()->addImageLibTexture("/test.bmp", false, ss);
		
        }