void CreatePlane(GameObject& obj, Vector4 worldPos, const char* texture) { Vertex v00, v01, v02, v03; v00.normal = Vector4::zero; v01.normal = Vector4::zero; v02.normal = Vector4::zero; v03.normal = Vector4::zero; Poly p0, p1; BitMap bm; if (texture != NULL && bm.Read(texture)) { p0.texture = bm; p1.texture = bm; v00.uv = Vector2(0.0f, 0.0f); v01.uv = Vector2(1.0f, 0.0f); v02.uv = Vector2(0.0f, 1.0f); v03.uv = Vector2(1.0f, 1.0f); } else { v00.color = ColourValue::Gray; v01.color = ColourValue::Gray; v02.color = ColourValue::Gray; v03.color = ColourValue::Gray; } v00.position = Vector4(1, 1, 1, 1); v01.position = Vector4(-1, 1, 1, 1); v02.position = Vector4(1, -1, 1, 1); v03.position = Vector4(-1, -1, 1, 1); obj.vertexListLocal[0] = v00; obj.vertexListLocal[1] = v01; obj.vertexListLocal[2] = v02; obj.vertexListLocal[3] = v03; p0.vertices = obj.vertexListTrans; p0.vertexIndexs[0] = 0; p0.vertexIndexs[1] = 1; p0.vertexIndexs[2] = 3; p1.vertices = obj.vertexListTrans; p1.vertexIndexs[0] = 3; p1.vertexIndexs[1] = 2; p1.vertexIndexs[2] = 0; // 设置物体属性 obj.polyCount = 2; obj.polyList[0] = p0; obj.polyList[1] = p1; obj.vertexCount = 4; obj.worldPos = worldPos; obj.ComputeVertexNormals(); }
void CreateCube(GameObject& obj, Vector4 worldPos, const char* texture) { Vertex v00, v01, v02, v03; Vertex v10, v11, v12, v13; Vertex v20, v21, v22, v23; Vertex v30, v31, v32, v33; Vertex v40, v41, v42, v43; Vertex v50, v51, v52, v53; v00.normal = Vector4::zero; v01.normal = Vector4::zero; v02.normal = Vector4::zero; v03.normal = Vector4::zero; v10.normal = Vector4::zero; v11.normal = Vector4::zero; v12.normal = Vector4::zero; v13.normal = Vector4::zero; v20.normal = Vector4::zero; v21.normal = Vector4::zero; v22.normal = Vector4::zero; v23.normal = Vector4::zero; v30.normal = Vector4::zero; v31.normal = Vector4::zero; v32.normal = Vector4::zero; v33.normal = Vector4::zero; v40.normal = Vector4::zero; v41.normal = Vector4::zero; v42.normal = Vector4::zero; v43.normal = Vector4::zero; v50.normal = Vector4::zero; v51.normal = Vector4::zero; v52.normal = Vector4::zero; v53.normal = Vector4::zero; Poly p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11; BitMap bm; if (texture != NULL && bm.Read(texture)) { cube_texture = bm; p0.texture = bm; p1.texture = bm; p2.texture = bm; p3.texture = bm; p4.texture = bm; p5.texture = bm; p6.texture = bm; p7.texture = bm; p8.texture = bm; p9.texture = bm; p10.texture = bm; p11.texture = bm; v00.uv = Vector2(0.0f, 0.0f); v01.uv = Vector2(1.0f, 0.0f); v02.uv = Vector2(0.0f, 1.0f); v03.uv = Vector2(1.0f, 1.0f); v10.uv = Vector2(0.0f, 0.0f); v11.uv = Vector2(1.0f, 0.0f); v12.uv = Vector2(0.0f, 1.0f); v13.uv = Vector2(1.0f, 1.0f); v20.uv = Vector2(0.0f, 0.0f); v21.uv = Vector2(1.0f, 0.0f); v22.uv = Vector2(0.0f, 1.0f); v23.uv = Vector2(1.0f, 1.0f); v30.uv = Vector2(0.0f, 0.0f); v31.uv = Vector2(1.0f, 0.0f); v32.uv = Vector2(0.0f, 1.0f); v33.uv = Vector2(1.0f, 1.0f); v40.uv = Vector2(0.0f, 0.0f); v41.uv = Vector2(1.0f, 0.0f); v42.uv = Vector2(0.0f, 1.0f); v43.uv = Vector2(1.0f, 1.0f); v50.uv = Vector2(0.0f, 0.0f); v51.uv = Vector2(1.0f, 0.0f); v52.uv = Vector2(0.0f, 1.0f); v53.uv = Vector2(1.0f, 1.0f); } else { v00.color = ColourValue::Gray; v01.color = ColourValue::Gray; v02.color = ColourValue::Gray; v03.color = ColourValue::Gray; v10.color = ColourValue::Gray; v11.color = ColourValue::Gray; v12.color = ColourValue::Gray; v13.color = ColourValue::Gray; v20.color = ColourValue::Gray; v21.color = ColourValue::Gray; v22.color = ColourValue::Gray; v23.color = ColourValue::Gray; v30.color = ColourValue::Gray; v31.color = ColourValue::Gray; v32.color = ColourValue::Gray; v33.color = ColourValue::Gray; v40.color = ColourValue::Gray; v41.color = ColourValue::Gray; v42.color = ColourValue::Gray; v43.color = ColourValue::Gray; v50.color = ColourValue::Gray; v51.color = ColourValue::Gray; v52.color = ColourValue::Gray; v53.color = ColourValue::Gray; } v00.position = Vector4(1, 1, 1, 1); v01.position = Vector4(-1, 1, 1, 1); v02.position = Vector4(1, -1, 1, 1); v03.position = Vector4(-1, -1, 1, 1); v10.position = Vector4(1, -1, 1, 1); v11.position = Vector4(-1, -1, 1, 1); v12.position = Vector4(1, -1, -1, 1); v13.position = Vector4(-1, -1, -1, 1); v20.position = Vector4(1, 1, 1, 1); v21.position = Vector4(1, -1, 1, 1); v22.position = Vector4(1, 1, -1, 1); v23.position = Vector4(1, -1, -1, 1); v30.position = Vector4(-1, -1, 1, 1); v31.position = Vector4(-1, 1, 1, 1); v32.position = Vector4(-1, -1, -1, 1); v33.position = Vector4(-1, 1, -1, 1); v40.position = Vector4(1, -1, -1, 1); v41.position = Vector4(-1, -1, -1, 1); v42.position = Vector4(1, 1, -1, 1); v43.position = Vector4(-1, 1, -1, 1); v50.position = Vector4(1, 1, -1, 1); v51.position = Vector4(-1, 1, -1, 1); v52.position = Vector4(1, 1, 1, 1); v53.position = Vector4(-1, 1, 1, 1); obj.vertexListLocal[0] = v00; obj.vertexListLocal[1] = v01; obj.vertexListLocal[2] = v02; obj.vertexListLocal[3] = v03; obj.vertexListLocal[4] = v10; obj.vertexListLocal[5] = v11; obj.vertexListLocal[6] = v12; obj.vertexListLocal[7] = v13; obj.vertexListLocal[8] = v20; obj.vertexListLocal[9] = v21; obj.vertexListLocal[10] = v22; obj.vertexListLocal[11] = v23; obj.vertexListLocal[12] = v30; obj.vertexListLocal[13] = v31; obj.vertexListLocal[14] = v32; obj.vertexListLocal[15] = v33; obj.vertexListLocal[16] = v40; obj.vertexListLocal[17] = v41; obj.vertexListLocal[18] = v42; obj.vertexListLocal[19] = v43; obj.vertexListLocal[20] = v50; obj.vertexListLocal[21] = v51; obj.vertexListLocal[22] = v52; obj.vertexListLocal[23] = v53; p0.vertices = obj.vertexListTrans; p0.vertexIndexs[0] = 0; p0.vertexIndexs[1] = 1; p0.vertexIndexs[2] = 3; p1.vertices = obj.vertexListTrans; p1.vertexIndexs[0] = 3; p1.vertexIndexs[1] = 2; p1.vertexIndexs[2] = 0; p2.vertices = obj.vertexListTrans; p2.vertexIndexs[0] = 4; p2.vertexIndexs[1] = 5; p2.vertexIndexs[2] = 7; p3.vertices = obj.vertexListTrans; p3.vertexIndexs[0] = 7; p3.vertexIndexs[1] = 6; p3.vertexIndexs[2] = 4; p4.vertices = obj.vertexListTrans; p4.vertexIndexs[0] = 8; p4.vertexIndexs[1] = 9; p4.vertexIndexs[2] = 11; p5.vertices = obj.vertexListTrans; p5.vertexIndexs[0] = 11; p5.vertexIndexs[1] = 10; p5.vertexIndexs[2] = 8; p6.vertices = obj.vertexListTrans; p6.vertexIndexs[0] = 12; p6.vertexIndexs[1] = 13; p6.vertexIndexs[2] = 15; p7.vertices = obj.vertexListTrans; p7.vertexIndexs[0] = 15; p7.vertexIndexs[1] = 14; p7.vertexIndexs[2] = 12; p8.vertices = obj.vertexListTrans; p8.vertexIndexs[0] = 16; p8.vertexIndexs[1] = 17; p8.vertexIndexs[2] = 19; p9.vertices = obj.vertexListTrans; p9.vertexIndexs[0] = 19; p9.vertexIndexs[1] = 18; p9.vertexIndexs[2] = 16; p10.vertices = obj.vertexListTrans; p10.vertexIndexs[0] = 20; p10.vertexIndexs[1] = 21; p10.vertexIndexs[2] = 23; p11.vertices = obj.vertexListTrans; p11.vertexIndexs[0] = 23; p11.vertexIndexs[1] = 22; p11.vertexIndexs[2] = 20; // 设置物体属性 obj.polyCount = 12; obj.polyList[0] = p0; obj.polyList[1] = p1; obj.polyList[2] = p2; obj.polyList[3] = p3; obj.polyList[4] = p4; obj.polyList[5] = p5; obj.polyList[6] = p6; obj.polyList[7] = p7; obj.polyList[8] = p8; obj.polyList[9] = p9; obj.polyList[10] = p10; obj.polyList[11] = p11; obj.vertexCount = 24; obj.worldPos = worldPos; obj.ComputeVertexNormals(); }