void CreateCube(float xShift, float yShift, float zShift) { float edgeLength = 25.0f * scale; M3DVector3f bodenVertices[8]; M3DVector4f bodenColors[8]; m3dLoadVector3(bodenVertices[0], -edgeLength + xShift, -edgeLength + yShift, -edgeLength + zShift); m3dLoadVector3(bodenVertices[1], edgeLength + xShift, -edgeLength + yShift, -edgeLength + zShift); m3dLoadVector3(bodenVertices[2], edgeLength + xShift, edgeLength + yShift, -edgeLength + zShift); m3dLoadVector3(bodenVertices[3], -edgeLength + xShift, edgeLength + yShift, -edgeLength + zShift); m3dLoadVector3(bodenVertices[4], -edgeLength + xShift, edgeLength + yShift, edgeLength + zShift); m3dLoadVector3(bodenVertices[5], -edgeLength + xShift, -edgeLength + yShift, edgeLength + zShift); m3dLoadVector3(bodenVertices[6], edgeLength + xShift, -edgeLength + yShift, edgeLength + zShift); m3dLoadVector3(bodenVertices[7], edgeLength + xShift, -edgeLength + yShift, -edgeLength + zShift); m3dLoadVector4(bodenColors[0], 0.0f, 0.0f, 0.5f, 1); m3dLoadVector4(bodenColors[1], 0.0f, 0.0f, 0.5f, 1); m3dLoadVector4(bodenColors[2], 0.0f, 0.0f, 0.5f, 1); m3dLoadVector4(bodenColors[3], 0.0f, 0.0f, 0.5f, 1); m3dLoadVector4(bodenColors[4], 0.0f, 0.0f, 0.7f, 1); m3dLoadVector4(bodenColors[5], 0.0f, 0.0f, 0.7f, 1); m3dLoadVector4(bodenColors[6], 0.0f, 0.0f, 0.7f, 1); m3dLoadVector4(bodenColors[7], 0.0f, 0.0f, 0.7f, 1); cboden.Begin(GL_TRIANGLE_FAN, 8); cboden.CopyVertexData3f(bodenVertices); cboden.CopyColorData4f(bodenColors); cboden.End(); M3DVector3f deckenVertices[8]; M3DVector4f deckenColors[8]; m3dLoadVector3(deckenVertices[0], edgeLength + xShift, edgeLength + yShift, edgeLength + zShift); m3dLoadVector3(deckenVertices[1], edgeLength + xShift, -edgeLength + yShift, -edgeLength + zShift); m3dLoadVector3(deckenVertices[2], edgeLength + xShift, -edgeLength + yShift, edgeLength + zShift); m3dLoadVector3(deckenVertices[3], -edgeLength + xShift, -edgeLength + yShift, edgeLength + zShift); m3dLoadVector3(deckenVertices[4], -edgeLength + xShift, edgeLength + yShift, edgeLength + zShift); m3dLoadVector3(deckenVertices[5], -edgeLength + xShift, edgeLength + yShift, -edgeLength + zShift); m3dLoadVector3(deckenVertices[6], edgeLength + xShift, edgeLength + yShift, -edgeLength + zShift); m3dLoadVector3(deckenVertices[7], edgeLength + xShift, -edgeLength + yShift, -edgeLength + zShift); m3dLoadVector4(deckenColors[0], 0.7f, 0.2f, 0.0f, 1); m3dLoadVector4(deckenColors[1], 0.7f, 0.2f, 0.0f, 1); m3dLoadVector4(deckenColors[2], 0.7f, 0.2f, 0.0f, 1); m3dLoadVector4(deckenColors[3], 0.7f, 0.0f, 0.0f, 1); m3dLoadVector4(deckenColors[4], 0.7f, 0.0f, 0.0f, 1); m3dLoadVector4(deckenColors[5], 0.7f, 0.0f, 0.0f, 1); m3dLoadVector4(deckenColors[6], 0.7f, 0.0f, 0.0f, 1); m3dLoadVector4(deckenColors[7], 0.7f, 0.2f, 0.0f, 1); decke.Begin(GL_TRIANGLE_FAN, 8); decke.CopyVertexData3f(deckenVertices); decke.CopyColorData4f(deckenColors); decke.End(); }
void SetupRC() { // Blue background glClearColor(0.0f, 0.0f, 1.0f, 1.0f); shaderManager.InitializeStockShaders(); GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }; GLfloat vColors[] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f }; triangleBatch.Begin(GL_TRIANGLES, 3); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.CopyColorData4f(vColors); triangleBatch.End(); myIdentityShader = gltLoadShaderPairWithAttributes("ShadedIdentity.vp", "ShadedIdentity.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_COLOR, "vColor"); }
// This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { glClearColor(0.7f, 0.7f, 0.7f, 1.0f ); shaderManager.InitializeStockShaders(); // Load up a triangle triangleBatch.Begin(GL_TRIANGLES, 3); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.CopyColorData4f(vColors); triangleBatch.End(); }
void SetupRC() { glClearColor(0, 0, 0, 1); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); gltMakeSphere(sphereBatch, 0.4, 20, 20); gltMakeCube(cubeBatch, 0.3); // Load up a triangle GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }; GLfloat vColors [] = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f }; triangleBatch.Begin(GL_TRIANGLES, 3); triangleBatch.CopyVertexData3f(vVerts); triangleBatch.CopyColorData4f(vColors); triangleBatch.End(); mWcgCube.SetupCube(); /*transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);*/ cameraFrame.MoveForward(-3.0f); m3dLoadIdentity44(mRotation); myShader = gltLoadShaderPairWithAttributes("shader.vp", "shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_COLOR, "vColor"); locMVP = glGetUniformLocation(myShader, "mvpMatrix"); }
void CreateSphere(float xShift, float yShift, float zShift) { float radius = 50.0f * scale; float diameter = radius * 2; GLfloat x, z; M3DVector3f* bodyVertices = new M3DVector3f[sphereArraySize * 2]; M3DVector4f* bodyColors = new M3DVector4f[sphereArraySize * 2]; m3dLoadVector3(bodyVertices[0], xShift, radius - diameter/tesselation + yShift, zShift); m3dLoadVector3(bodyVertices[1], 0.0f + xShift, radius - 2*diameter/tesselation + yShift, zShift); m3dLoadVector4(bodyColors[0], 0.91f, 0.70f, 0.54f, 1.0f); m3dLoadVector4(bodyColors[1], 0.91f, 0.70f, 0.54f, 1.0f); int i = 1; int colorIndex = 0; // Kugel vertikal entlang der Breitengrade durchlaufen for (GLfloat latitude = 0.0f; latitude <= GL_PI; latitude += (GL_PI / tesselation)) { float sliceRadius = radius * sin(latitude); GLfloat y = radius * cos(latitude) + yShift; // Kugelscheibe entlang der Laengengrade durchlaufen for (GLfloat longitude = 0.0f; longitude <= (2.0f*GL_PI); longitude += (GL_PI / tesselation)) { float upperRadius = sliceRadius; float lowerRadius = radius * sin(latitude + (GL_PI / tesselation)); x = cos(longitude); z = sin(longitude); m3dLoadVector3(bodyVertices[2 * i], x*upperRadius + xShift, y, z*upperRadius + zShift); m3dLoadVector3(bodyVertices[2 * i + 1], x*lowerRadius + xShift, radius * cos(latitude + GL_PI/tesselation), z*lowerRadius + zShift); //fuer Abgabe einkommentieren :) //if (colorIndex % 2 == 0) { // m3dLoadVector4(bodyColors[2 * i], 1.0f, 0.8f, 0.2f, 1.0f); // m3dLoadVector4(bodyColors[2 * i + 1], 1.0f, 0.8f, 0.2f, 1.0f); //} //else { // m3dLoadVector4(bodyColors[2 * i], 0.235f, 0.235f, 0.235f, 1.0f); // m3dLoadVector4(bodyColors[2 * i + 1], 0.235f, 0.235f, 0.235f, 1.0f); //} // fuer Maennchen einkommentieren :) m3dLoadVector4(bodyColors[2 * i], 0.91f, 0.70f, 0.54f, 1.0f); m3dLoadVector4(bodyColors[2 * i + 1], 0.91f, 0.70f, 0.54f, 1.0f); i++; } colorIndex++; } sphereBody.Reset(); sphereBody.Begin(GL_TRIANGLE_STRIP, sphereArraySize); sphereBody.CopyVertexData3f(bodyVertices); sphereBody.CopyColorData4f(bodyColors); sphereBody.End(); delete[] bodyVertices; delete[] bodyColors; }
void CreateCylinder(float xShift, float yShift, float zShift) { GLfloat x, z, angle; float radius = 50.0f * scale; int i = 1; M3DVector3f* fussVertices = new M3DVector3f[arraySize]; M3DVector3f* kopfVertices = new M3DVector3f[arraySize]; M3DVector3f* planeVertices = new M3DVector3f[doubleArraySize]; M3DVector4f* fussColors = new M3DVector4f[arraySize]; M3DVector4f* kopfColors = new M3DVector4f[arraySize]; M3DVector4f* planeColors = new M3DVector4f[doubleArraySize]; m3dLoadVector3(fussVertices[0], xShift, -radius + yShift, zShift); m3dLoadVector3(kopfVertices[0], xShift, radius + yShift, zShift); m3dLoadVector3(planeVertices[0], xShift, -radius + yShift, zShift); m3dLoadVector3(planeVertices[1], xShift, radius + yShift, zShift); m3dLoadVector4(fussColors[0], 0.0f, 0.7f, 0.0f, 1); m3dLoadVector4(kopfColors[0], 0.0f, 0.5f, 0.1f, 1); m3dLoadVector4(planeColors[0], 0.1f, 0.3f, 0.0f, 1); m3dLoadVector4(planeColors[1], 0.1f, 0.3f, 0.0f, 1); for (angle = 0.0f; angle <= (2.0f*GL_PI); angle += (GL_PI / tesselation)) { // Berechne x und y Positionen des naechsten Vertex x = radius*sin(angle); z = radius*cos(angle); m3dLoadVector3(fussVertices[i], x + xShift, -radius + yShift, z + zShift); m3dLoadVector3(kopfVertices[i], -x, radius + yShift, z + zShift); m3dLoadVector3(planeVertices[2 * i], x + xShift, -radius + yShift, z + zShift); m3dLoadVector3(planeVertices[2 * i + 1], x + xShift, radius + yShift, z + zShift); m3dLoadVector4(fussColors[i], 0.0f, 0.7f, 0.0f, 1.0f); m3dLoadVector4(kopfColors[i], 0.0f, 0.5f, 0.1f, 1.0f); m3dLoadVector4(planeColors[2 * i], 0.1f, 0.3f, 0.0f, 1.0f); m3dLoadVector4(planeColors[2 * i + 1], 0.1f, 0.3f, 0.0f, 1.0f); i++; } fuss.Begin(GL_TRIANGLE_FAN, arraySize); kopf.Begin(GL_TRIANGLE_FAN, arraySize); plane.Begin(GL_TRIANGLE_STRIP, doubleArraySize); fuss.CopyVertexData3f(fussVertices); fuss.CopyColorData4f(fussColors); kopf.CopyVertexData3f(kopfVertices); kopf.CopyColorData4f(kopfColors); plane.CopyVertexData3f(planeVertices); plane.CopyColorData4f(planeColors); fuss.End(); kopf.End(); plane.End(); delete[] fussVertices; delete[] fussColors; delete[] kopfVertices; delete[] kopfColors; delete[] planeVertices; delete[] planeColors; }
void CreateCone(float xShift, float yShift, float zShift) { //18 Vertices anlegen M3DVector3f* konusVertices = new M3DVector3f[18]; M3DVector4f* konusColors = new M3DVector4f[18]; float radius = 50.0f * scale; float height = 75.0f * scale; // Die Spitze des Konus ist ein Vertex, den alle Triangles gemeinsam haben; // um einen Konus anstatt einen Kreis zu produzieren muss der Vertex einen positiven z-Wert haben m3dLoadVector3(konusVertices[0], xShift, height + yShift, zShift); m3dLoadVector4(konusColors[0], 0.0f, 1.0f, 0.0f, 1.0f); // Kreise um den Mittelpunkt und spezifiziere Vertices entlang des Kreises // um einen Triangle_Fan zu erzeugen int iPivot = 1; int i = 1; for (float angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI / 8)) { // Berechne x und y Positionen des naechsten Vertex float x = radius*cos(angle); float z = radius*sin(angle); // Alterniere die Farbe zwischen Rot und Gruen if ((iPivot % 2) == 0) m3dLoadVector4(konusColors[i],0.9f, 1.0f, 0.9f, 1.0f); else m3dLoadVector4(konusColors[i], 0.0f, 0.4f, 0.2f, 1.0f); // Inkrementiere iPivot um die Farbe beim naechsten mal zu wechseln iPivot++; // Spezifiziere den naechsten Vertex des Triangle_Fans m3dLoadVector3(konusVertices[i], x + xShift, yShift, z + zShift); i++; } konus.Begin(GL_TRIANGLE_FAN, 18); konus.CopyVertexData3f(konusVertices); konus.CopyColorData4f(konusColors); konus.End(); delete[] konusVertices; delete[] konusColors; // Erzeuge einen weiteren Triangle_Fan um den Boden zu bedecken M3DVector3f* bodenVertices = new M3DVector3f[18]; M3DVector4f* bodenColors = new M3DVector4f[18]; // Das Zentrum des Triangle_Fans ist im Ursprung m3dLoadVector3(bodenVertices[0], 0, 0, zShift); m3dLoadVector4(bodenColors[0], 1, 0, 0, 1); i = 1; for (float angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI / 8)) { // Berechne x und y Positionen des naechsten Vertex float x = radius*sin(angle); float z = radius*cos(angle); m3dLoadVector4(bodenColors[i], 0.0f, 0.2f, 0.0f, 1.0f); // Inkrementiere iPivot um die Farbe beim naechsten mal zu wechseln iPivot++; // Spezifiziere den naechsten Vertex des Triangle_Fans m3dLoadVector3(bodenVertices[i], x + xShift, yShift, z + zShift); i++; } kboden.Begin(GL_TRIANGLE_FAN, 18); kboden.CopyVertexData3f(bodenVertices); kboden.CopyColorData4f(bodenColors); kboden.End(); delete[] bodenVertices; delete[] bodenColors; }