void Rain::Sprite::RenderShader(float texStartU,float texStartV,float width,float height, bool wrap){ shader->Begin(); shader->SetUniform1i("spriteTex",0); shader->SetUniform3f("colorKey", 1.0f,0.0f,1.0f); glActiveTexture(GL_TEXTURE0); if (wrap) { tex->bindTextureWrap(); } else { tex->bindTexture(); } glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); M3DVector3f verts[4]; M3DVector2f texUVs[4]; float x = pos[0]; float y = pos[1]; m3dLoadVector3(verts[0],x + width, y, 0.0f); m3dLoadVector3(verts[1],x , y, 0.0f); m3dLoadVector3(verts[2],x , y + height, 0.0f); m3dLoadVector3(verts[3],x + width, y + height, 0.0f); float leftx, lefty,rightx,righty; leftx = texStartU / width; lefty = (side - texStartV) / side ; rightx = (texStartU + width) / side; righty = (side - texStartV - height) / side ; m3dLoadVector2(texUVs[0],rightx, lefty); m3dLoadVector2(texUVs[1],leftx,lefty); m3dLoadVector2(texUVs[2],leftx,righty ); m3dLoadVector2(texUVs[3],rightx,righty ); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,sizeof(M3DVector3f),&verts[0][0]); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2,GL_FLOAT,sizeof(M3DVector2f),&texUVs[0][0]); glDrawArrays(GL_QUADS, 0, 4); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); shader->End(); }
void initEnvironment() { outFileClothModel(); inFileClothModel(); M3DVector3f shift; m3dLoadVector3(shift, -WIDNUMBER*EDGELENGTH/2, 200.0f, - GAPLENGTH/2); shiftClothModelPosition(shift); initManModel(); initClothModel(); getClothModelCenter(); }
void Rain::Sprite::RenderShader(){ shader->Begin(); shader->SetUniform1i("spriteTex",0); shader->SetUniform3f("colorKey", 1.0f,0.0f,1.0f); glActiveTexture(GL_TEXTURE0); tex->bindTexture(); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); M3DVector3f verts[4]; M3DVector2f texUVs[4]; float x = pos[0]; float y = pos[1]; m3dLoadVector3(verts[0],x + side, y, 0.0f); m3dLoadVector3(verts[1],x , y, 0.0f); m3dLoadVector3(verts[2],x , y + side, 0.0f); m3dLoadVector3(verts[3],x + side, y + side, 0.0f); m3dLoadVector2(texUVs[0],1.0f, 1.0f); m3dLoadVector2(texUVs[1],0.0f,1.0f); m3dLoadVector2(texUVs[2],0.0f,0.0f); m3dLoadVector2(texUVs[3],1.0f,0.0f); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT,sizeof(M3DVector3f),&verts[0][0]); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2,GL_FLOAT,sizeof(M3DVector2f),&texUVs[0][0]); glDrawArrays(GL_QUADS, 0, 4); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); shader->End(); }
void sewClothModel() { M3DVector3f temp, displacement; for (int i = 0; i < PTCAMT; i ++) { m3dLoadVector3(displacement, 0.0f, 0.0f, 0.0f); clearForce(i); getInternalForce(i); //sew together getTensionForce(i, ClothCenter, 0.01f); m3dScaleVector3(ClothLnk[i].force, TensionCoefficient); nextPosition(i); m3dSubtractVectors3(temp, ClothLnk[i].next_position, ClothLnk[i].position); m3dAddVectors3(displacement, displacement, temp); } m3dScaleVector3(displacement, (GLfloat)800000/PTCAMT); //printf(" total displace: %.1f %.1f %.1f\n", displacement[0], displacement[1], displacement[2]); m3dAddVectors3(ClothCenter, ClothCenter, displacement); //m3dLoadVector3(TotalDisplacement, 0.0f, 0.0f, 0.0f); refreshPosition(); }
void ObjectsLoader::Init( CompositeNode* l, MeshFileLoader* MeshLoader) { // Init Camera Camera* c = reinterpret_cast<Camera*>(l->GetByName("GlobalCamera")); M3DVector3f pos; m3dLoadVector3( pos, 0.0f, 0.0f, 10.0f ); c->SetPosition( pos ); c->SetPerspective(45.0f,(GLfloat)800/(GLfloat)600,0.1f,100.0f); // Load some Meshes Mesh* Rose = MeshLoader->Load("Objects/rose+vase.obj"); Mesh* Soccerball = MeshLoader->Load("Objects/soccerball.obj"); Mesh* Slotmachine = MeshLoader->Load("Objects/slot_machine.obj"); Mesh* F16 = MeshLoader->Load("Objects/f-16.obj"); Mesh* Shuttle = MeshLoader->Load("Objects/shuttle.obj"); Mesh* Cessna = MeshLoader->Load("Objects/cessna.obj"); // Build up Scenegraph c->AddChild( (new Transform(string("SlotMachineTransform")))->AddChild( (new Geometry(Slotmachine, string("SlotMachine"))) )); c->AddChild( (new Transform(string("RoseTransform")))->AddChild( (new Geometry(Rose, "Rose"))) ); c->AddChild( (new Transform(string("SoccerballTransform")))->AddChild( (new Geometry(Soccerball, "Soccerball"))) ); c->AddChild( (new Transform(string("F16Transform")))->AddChild( (new Geometry(F16, "F16"))) ); c->AddChild( (new Transform(string("ShuttleTransform")))->AddChild( (new Geometry(Shuttle, "Shuttle"))) ); c->AddChild( (new Transform(string("CessnaTransform")))->AddChild( (new Geometry(Cessna, "Cessna"))) ); Transform* t = reinterpret_cast<Transform*>(l->GetByName("SlotMachineTransform")); t->Translate(-3.0f, 0.0f, 0.0f); t->Scale(0.1f, 0.1f, 0.1f); t = reinterpret_cast<Transform*>(l->GetByName("RoseTransform")); t->Translate(2.0f, 0.0f, 0.0f); t->Scale(0.02f, 0.02f, 0.02f); t = reinterpret_cast<Transform*>(l->GetByName("SoccerballTransform")); t->Scale(0.15f, 0.15f, 0.15f); t = reinterpret_cast<Transform*>(l->GetByName("F16Transform")); t->Translate(4.0f, 1.2f, 0.0f); t->Scale(0.4f, 0.4f, 0.4f); t = reinterpret_cast<Transform*>(l->GetByName("ShuttleTransform")); t->Translate(-3.5f, 2.3f, 0.0f); t->Scale(0.2f, 0.2f, 0.2f); t = reinterpret_cast<Transform*>(l->GetByName("CessnaTransform")); t->Translate(0.0f, 2.5f, 0.0f); t->Scale(0.05f, 0.05f, 0.05f); }
void needStop(int currentPtc) { if ((GLfloat)m3dGetVectorLength(ClothLnk[currentPtc].force) <= minForce) { m3dLoadVector3(ClothLnk[currentPtc].force, 0.0f, 0.0f, 0.0f); m3dCopyVector3(ClothLnk[currentPtc].pre_position, ClothLnk[currentPtc].position); } }
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 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 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; }
void Init(CompositeNode* root, MeshFileLoader* MeshLoader ) { // glDisable(GL_CULL_FACE); // glEnable(GL_CULL_FACE); // glCullFace(GL_BACK); // m = mfl->Load("Objects/cube.obj"); // g = new Geometry(m, "Geometry"); // g->SetMesh( m ); Mesh* Magnolia = MeshLoader->Load("Objects/magnolia.obj"); Magnolia->Scale(0.03f); Mesh* Rose = MeshLoader->Load("Objects/rose+vase.obj"); Rose->Scale(0.03f); //Mesh* Dolphins = MeshLoader->Load("Objects/dolphins.obj"); //Dolphins->Scale(0.01f); Mesh* Skyscraper = MeshLoader->Load("Objects/skyscraper.obj"); Skyscraper->Scale(0.04f); M3DVector3f pos; m3dLoadVector3( pos, 0.0f, 0.0f, 50.0f ); if (_camera) DLOG(INFO) << "_camera address: " << _camera << endl; _camera->SetPosition( pos ); Vector4 color( 1.0f, 1.0f, 1.0f, 1.0f ); _light->SetDiffuse( color ); _light->SetAmbient( color ); // M3DVector3f pos; // m3dLoadVector3( pos, 0.0f, 0.0f, 10.0f ); // Init Camera // Camera* c = reinterpret_cast<Camera*>(l->GetByName("GlobalCamera")); // c->SetPosition( pos ); // c->SetPerspective(45.0f,(GLfloat)800/(GLfloat)600,0.1f,100.0f); // Build Up Scenegraph _camera->AddChild( (new Transform(string("MagnoliaTransform")))->AddChild( (new Geometry(Magnolia, string("Magnolia"))) )); _camera->AddChild( (new Transform(string("RoseTransform")))->AddChild( (new Geometry(Rose, "Rose"))) ); _camera->AddChild( (new Transform(string("SkyscraperTransform")))->AddChild( (new Geometry(Skyscraper, "Skyscraper"))) ); Transform* t = dynamic_cast<Transform*>(root->GetByName("MagnoliaTransform")); t->Rotate(20.0f, 1.0f, 1.0f, 1.0f); t->Translate(-3.0f, 0.0f, 0.0f); t = dynamic_cast<Transform*>(root->GetByName("RoseTransform")); t->Translate(2.0f, 0.0f, 0.0f); t->Rotate(20.0f, 1.0f, 1.0f, 1.0f); t->Scale(1.6f, 1.2f, 1.2f); t = dynamic_cast<Transform*>(root->GetByName("SkyscraperTransform")); t->Rotate(50.0f, 1.0f, 1.0f, 1.0f); update = t; UpdateVisitorFactory fact; visitor = fact.CreateTransformationVisitor( ROTATE, 1.0f, 0.0f, 0.0f, 0.01f ); visitor2 = fact.CreateTransformationVisitor( SCALE, 1.002f, 1.0f, 1.0f ); };