void Terrain::GenerateVerticesNormal()
{
    //Traverse through the vertices

    for(u32 vertexIndex = 0; vertexIndex < m_indexBuffer.m_indexData.size() - 3; vertexIndex += 3)
    {
        XCVec4 v1(m_vertexPosNormTexBuffer.m_vertexData[m_indexBuffer.m_indexData[vertexIndex]].Pos);
        XCVec4 v2(m_vertexPosNormTexBuffer.m_vertexData[m_indexBuffer.m_indexData[vertexIndex + 1]].Pos);
        XCVec4 v3(m_vertexPosNormTexBuffer.m_vertexData[m_indexBuffer.m_indexData[vertexIndex + 2]].Pos);

        XCVec4 vertexNormal = GetNormalFromPoints(v1, v2, v3);

        m_vertexPosNormTexBuffer.m_vertexData[m_indexBuffer.m_indexData[vertexIndex]].Norm = vertexNormal.GetUnaligned3();

        vertexNormal = GetNormalFromPoints(v2, v1, v3);
        m_vertexPosNormTexBuffer.m_vertexData[m_indexBuffer.m_indexData[vertexIndex + 1]].Norm = vertexNormal.GetUnaligned3();

        vertexNormal = GetNormalFromPoints(v3, v1, v2);
        m_vertexPosNormTexBuffer.m_vertexData[m_indexBuffer.m_indexData[vertexIndex + 2]].Norm, vertexNormal.GetUnaligned3();
    }
}
const Vector &GetNormalFromFace( int nFace )
{
	// ok, now check against all 6 faces
	
	Vector points[8];

	Assert( nFace>=0 && nFace<6 );

	PointsFromBox( Vector(0,0,0), Vector(1,1,1), points );

 	return GetNormalFromPoints( points[s_BoxFaces[nFace][0]], points[s_BoxFaces[nFace][1]],points[s_BoxFaces[nFace][2]] );
}
Example #3
0
File: LAB7.cpp Project: ntlone/Lab7
void DrawInsidePhyramid()
{
	CVector vertices[11] = {
		{ 0.0f, 0.0f, 9.9f }, // Góra figóry
		{ 0.0f, 1.9f, 0.0f }, //                1
		{ 1.4f, 1.4f, 0.0f }, //           10        2
		{ 1.9f, 0.0f, 0.0f }, //          9     0      3
		{ 1.6f, -1.1f, 0.0f }, //          8          4
		{ 0.9f, -1.4f, 0.0f }, //             7    5
		{ 0.0f, -1.9f, 0.0f }, //                6
		{ -0.9f, -1.4f, 0.0f }, //
		{ -1.6f, -1.1f, 0.0f }, //
		{ -1.9f, 0.0f, 0.0f }, //
		{ -1.4f, 1.4f, 0.0f }, //
	};

	CVector normals[11] = {
		{ 0.0f, 1.0f, 0.0f },
		GetNormalFromPoints(vertices[1], vertices[0], vertices[2]),
		GetNormalFromPoints(vertices[2], vertices[0], vertices[3]),
		GetNormalFromPoints(vertices[3], vertices[0], vertices[4]),
		GetNormalFromPoints(vertices[4], vertices[0], vertices[5]),
		GetNormalFromPoints(vertices[5], vertices[0], vertices[6]),
		GetNormalFromPoints(vertices[6], vertices[0], vertices[7]),
		GetNormalFromPoints(vertices[7], vertices[0], vertices[8]),
		GetNormalFromPoints(vertices[8], vertices[0], vertices[9]),
		GetNormalFromPoints(vertices[9], vertices[0], vertices[10]),
		GetNormalFromPoints(vertices[10], vertices[0], vertices[1])
	};

	glBegin(GL_TRIANGLES);

	glColor3f(1.0, 0.0, 0.0);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[1].vectors);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[2].vectors);

	glColor3f(0.0, 1.0, 0.0);
	glNormal3fv(normals[2].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[2].vectors);
	glVertex3fv(vertices[2].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[3].vectors);

	glColor3f(0.0, 0.0, 1.0);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[3].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[4].vectors);

	glColor3f(1.0, 1.0, 0.0);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[4].vectors);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[5].vectors);

	glColor3f(1.0, 0.0, 1.0);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[5].vectors);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[6].vectors);

	glColor3f(0.0, 1.0, 1.0);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[6].vectors);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[7].vectors);

	glColor3f(1.0, 1.0, 1.0);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[7].vectors);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[8].vectors);

	glColor3f(1.0, 0.5, 0.0);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[8].vectors);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[9].vectors);

	glColor3f(0.5, 1.0, 0.0);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[9].vectors);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[10].vectors);

	glColor3f(0.5, 1.0, 1.0);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[10].vectors);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[1].vectors);

	glEnd();
}
Example #4
0
File: LAB7.cpp Project: ntlone/Lab7
void DrawOutsidePhyramid()
{
	CVector vertices[11] = {
		{ 0.0f, 0.0f, 10.0f }, // Góra figóry
		{ 0.0f, 2.0f, 0.0f }, //                1
		{ 1.5f, 1.5f, 0.0f }, //           10        2
		{ 2.0f, 0.0f, 0.0f }, //          9     0      3
		{ 1.7f, -1.2f, 0.0f }, //          8          4
		{ 1.0f, -1.5f, 0.0f }, //            7      5
		{ 0.0f, -2.0f, 0.0f }, //               6
		{ -1.0f, -1.5f, 0.0f }, //
		{ -1.7f, -1.2f, 0.0f }, //
		{ -2.0f, 0.0f, 0.0f }, //
		{ -1.5f, 1.5f, 0.0f }, //
	};

	CVector normals[11] = {
		{ 0.0f, -1.0f, 0.0f },
		GetNormalFromPoints(vertices[2], vertices[0], vertices[1]),
		GetNormalFromPoints(vertices[3], vertices[0], vertices[2]),
		GetNormalFromPoints(vertices[4], vertices[0], vertices[3]),
		GetNormalFromPoints(vertices[5], vertices[0], vertices[4]),
		GetNormalFromPoints(vertices[6], vertices[0], vertices[5]),
		GetNormalFromPoints(vertices[7], vertices[0], vertices[6]),
		GetNormalFromPoints(vertices[8], vertices[0], vertices[7]),
		GetNormalFromPoints(vertices[9], vertices[0], vertices[8]),
		GetNormalFromPoints(vertices[10], vertices[0], vertices[9]),
		GetNormalFromPoints(vertices[1], vertices[0], vertices[10])
	};

	glBegin(GL_TRIANGLES);

	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[1].vectors);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[2].vectors);

	glNormal3fv(normals[2].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[2].vectors);
	glVertex3fv(vertices[2].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[3].vectors);

	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[3].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[4].vectors);

	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[4].vectors);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[5].vectors);

	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[5].vectors);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[6].vectors);

	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[6].vectors);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[7].vectors);

	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[7].vectors);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[8].vectors);

	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[8].vectors);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[9].vectors);

	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[9].vectors);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[10].vectors);

	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[10].vectors);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[1].vectors);

	glEnd();

	glBegin(GL_POLYGON);

	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[1].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[2].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[3].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[4].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[5].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[6].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[7].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[8].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[9].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[10].vectors);

	glEnd();
}