void CTrajectory::DrawPoint( const Ogre::Vector3& Pos ) { Ogre::Vector3 dx = mPointSize/2*Ogre::Vector3::UNIT_X; Ogre::Vector3 dy = mPointSize/2*Ogre::Vector3::UNIT_Y; Ogre::Vector3 dz = mPointSize/2*Ogre::Vector3::UNIT_Z; Ogre::Vector3 Vertices[8]; Vertices[0] = Pos + dx + dy + dz; Vertices[1] = Pos + dx - dy + dz; Vertices[2] = Pos + dx - dy - dz; Vertices[3] = Pos + dx + dy - dz; Vertices[4] = Pos - dx + dy + dz; Vertices[5] = Pos - dx + dy - dz; Vertices[6] = Pos - dx - dy - dz; Vertices[7] = Pos - dx - dy + dz; BuildQuad( Vertices, mColour ); BuildQuad( Vertices + 4, mColour ); BuildLine( Vertices[1], Vertices[7], mColour ); BuildLine( Vertices[2], Vertices[6], mColour ); BuildLine( Vertices[0], Vertices[4], mColour); BuildLine( Vertices[3], Vertices[5], mColour); Ogre::Vector3 Top[4] = { Vertices[0], Vertices[4], Vertices[7], Vertices[1] }; Ogre::Vector3 Bottom[4] = { Vertices[2], Vertices[6], Vertices[5], Vertices[3] }; Ogre::Vector3 Left[4] = { Vertices[1], Vertices[7], Vertices[6], Vertices[2] }; Ogre::Vector3 Right[4] = { Vertices[0], Vertices[3], Vertices[5], Vertices[4] }; BuildFilledQuad( Vertices, mColour, 0.5f ); BuildFilledQuad( Vertices + 4, mColour, 0.5f ); BuildFilledQuad( Top, mColour, 0.5f ); BuildFilledQuad( Bottom, mColour, 0.5f ); BuildFilledQuad( Left, mColour, 0.5f ); BuildFilledQuad( Right, mColour, 0.5f ); }
void ASimpleCubeActor::GenerateCube(FProceduralMeshData& MeshData, float Depth, float Width, float Height) { // NOTE: Unreal uses an upper-left origin UV // NOTE: This sample uses a simple UV mapping scheme where each face is the same // NOTE: For a normal facing towards us, be build the polygon CCW in the order 0-1-2 then 0-2-3 to complete the quad. // Remember in Unreal, X is forwards, Y is to your right and Z is up. // Calculate a half offset so we get correct center of object float DepthOffset = Depth / 2.0f; // X float WidthOffset = Width / 2.0f; // Y float HeightOffset = Height / 2.0f; // Z // Define the 8 corners of the cube FVector p0 = FVector(DepthOffset, WidthOffset, -HeightOffset); FVector p1 = FVector(DepthOffset, -WidthOffset, -HeightOffset); FVector p2 = FVector(DepthOffset, -WidthOffset, HeightOffset); FVector p3 = FVector(DepthOffset, WidthOffset, HeightOffset); FVector p4 = FVector(-DepthOffset, WidthOffset, -HeightOffset); FVector p5 = FVector(-DepthOffset, -WidthOffset, -HeightOffset); FVector p6 = FVector(-DepthOffset, -WidthOffset, HeightOffset); FVector p7 = FVector(-DepthOffset, WidthOffset, HeightOffset); // Now we create 6x faces, 4 vertices each int32 VertexCount = 6 * 4; MeshData.Vertices.AddUninitialized(VertexCount); MeshData.UVs.AddUninitialized(VertexCount); MeshData.Normals.AddUninitialized(VertexCount); MeshData.Tangents.AddUninitialized(VertexCount); int32 VertexOffset = 0; FVector Normal = FVector::ZeroVector; FProcMeshTangent Tangent = FProcMeshTangent(); // Front (+X) face: 0-1-2-3 Normal = FVector(1, 0, 0); Tangent = FProcMeshTangent(0, 1, 0); VertexOffset = BuildQuad(MeshData, p0, p1, p2, p3, VertexOffset, Normal, Tangent); // Back (-X) face: 5-4-7-6 Normal = FVector(-1, 0, 0); Tangent = FProcMeshTangent(0, -1, 0); VertexOffset = BuildQuad(MeshData, p5, p4, p7, p6, VertexOffset, Normal, Tangent); // Left (-Y) face: 1-5-6-2 Normal = FVector(0, -1, 0); Tangent = FProcMeshTangent(1, 0, 0); VertexOffset = BuildQuad(MeshData, p1, p5, p6, p2, VertexOffset, Normal, Tangent); // Right (+Y) face: 4-0-3-7 Normal = FVector(0, 1, 0); Tangent = FProcMeshTangent(-1, 0, 0); VertexOffset = BuildQuad(MeshData, p4, p0, p3, p7, VertexOffset, Normal, Tangent); // Top (+Z) face: 6-7-3-2 Normal = FVector(0, 0, 1); Tangent = FProcMeshTangent(0, 1, 0); VertexOffset = BuildQuad(MeshData, p6, p7, p3, p2, VertexOffset, Normal, Tangent); // Bottom (-Z) face: 1-0-4-5 Normal = FVector(0, 0, -1); Tangent = FProcMeshTangent(0, -1, 0); VertexOffset = BuildQuad(MeshData, p1, p0, p4, p5, VertexOffset, Normal, Tangent); }