OpenGLWidget::OpenGLWidget(MainWindow* mainWindow) : QOpenGLWidget{mainWindow} , m_axisLegendScene{mainWindow->app()} , m_width{0} , m_height{0} , m_currentLocation{} , m_previousLocation{} { this->setFocusPolicy(Qt::StrongFocus); m_contextMenu = new QMenu(this); QMenu* createMenu = m_contextMenu->addMenu("Create"); createMenu->addAction(tr("Box"), this, SLOT(createBox())); createMenu->addAction(tr("Cylinder"), this, SLOT(createCylinder())); createMenu->addAction(tr("Cone"), this, SLOT(createCone())); createMenu->addAction(tr("Sphere"), this, SLOT(createSphere())); m_contextMenu->addAction(tr("Import Mesh"), this, SLOT(importMesh())); QSurfaceFormat format = this->format(); format.setVersion(kOpenGLMajorVersion, kOpenGLMinorVersion); format.setProfile(QSurfaceFormat::CoreProfile); format.setDepthBufferSize(32); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); LOG(INFO) << fmt::format("Setting format with OpenGL version {}.{}", kOpenGLMajorVersion, kOpenGLMinorVersion); this->setFormat(format); }
void readGeometry(scene_data* scene, const boost::property_tree::ptree& pt) { boost::property_tree::ptree::const_iterator iter = pt.begin(); for (; iter != pt.end(); ++iter) { std::string name = iter->first; geometry* geom; if (name == "cube") geom = createBox(); else if (name == "tetrahedron") geom = createTetrahedron(); else if (name == "pyramid") geom = createPyramid(); else if (name == "disk") { int slices = iter->second.get_child("slices").get_value<int>(); geom = createDisk(slices); } else if (name == "cylinder") { int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createCylinder(stacks, slices); } else if (name == "sphere") { int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createSphere(stacks, slices); } else if (name == "torus") { float radius = iter->second.get_child("radius").get_value<float>(); int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createTorus(radius, stacks, slices); } else if (name == "plane") { int width = iter->second.get_child("width").get_value<int>(); int depth = iter->second.get_child("depth").get_value<int>(); geom = createPlane(width, depth); } else if (name == "sierpinski") { int divisions = iter->second.get_child("divisions").get_value<int>(); geom = createSierpinski(divisions); } else { std::cerr << "Error - Geometry type not recognised: " << name << std::endl; exit(EXIT_FAILURE); } scene->geometry[name] = geom; } }
void sceneInit(void) { GLint result; /* create program object and attach shaders */ g_program = glCreateProgram(); shaderAttachFromFile(g_program, GL_VERTEX_SHADER, "data/shader.vp"); shaderAttachFromFile(g_program, GL_FRAGMENT_SHADER, "data/shader.fp"); /* link the program and make sure that there were no errors */ glLinkProgram(g_program); glGetProgramiv(g_program, GL_LINK_STATUS, &result); if(result == GL_FALSE) { GLint length; char *log; /* get the program info log */ glGetProgramiv(g_program, GL_INFO_LOG_LENGTH, &length); log = malloc(length); glGetProgramInfoLog(g_program, length, &result, log); /* print an error message and the info log */ fprintf(stderr, "sceneInit(): Program linking failed: %s\n", log); free(log); /* delete the program */ glDeleteProgram(g_program); g_program = 0; } /* get uniform locations */ g_programCameraPositionLocation = glGetUniformLocation(g_program, "cameraPosition"); g_programLightPositionLocation = glGetUniformLocation(g_program, "lightPosition"); g_programLightColorLocation = glGetUniformLocation(g_program, "lightColor"); /* set up red/green/blue lights */ g_lightColor[0] = 1.0f; g_lightColor[1] = 0.0f; g_lightColor[2] = 0.0f; g_lightColor[3] = 0.0f; g_lightColor[4] = 1.0f; g_lightColor[5] = 0.0f; g_lightColor[6] = 0.0f; g_lightColor[7] = 0.0f; g_lightColor[8] = 1.0f; /* create cylinder */ createCylinder(36); /* do the first cycle to initialize positions */ g_lightRotation = 0.0f; sceneCycle(); /* setup camera */ g_cameraPosition[0] = 0.0f; g_cameraPosition[1] = 0.0f; g_cameraPosition[2] = 4.0f; glLoadIdentity(); glTranslatef(-g_cameraPosition[0], -g_cameraPosition[1], -g_cameraPosition[2]); }
GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) { upSphereCone = downSphereCone = cylinderVertices = diskVertices = sphereVertices = coneVertices = 0; cylinderSize = diskSize = sphereVerticesSize = sphereConeSize = coneSize = 0; createSphere(1.0f, 10, 10); createCone(0.5f, 0.5f, 6); createDisk(0.5f, 6); createCylinder(0.9f, 0.1f, 0.0f, 50); program = new QOpenGLShaderProgram(this); setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::SampleBuffers | QGL::NoDeprecatedFunctions)); modelView.setColumn(3, QVector4D(-0.5, -0.5, 0, 1)); }
void InitializePolygonlists(void) { int i; // The road polylistRoad = CreatePolylist(10); loadPolygonalObject(polylistRoad, "road.obj", texture_names, 1.0, 0.0, 0.0, 0.0); // We load the ground object twice, but use a different translation to put it once // on either side of the road polylistGround1 = CreatePolylist(10); loadPolygonalObject(polylistGround1, "ground.obj", texture_names, 1.0, 0.0, 0.0, -55.0); polylistGround2 = CreatePolylist(10); loadPolygonalObject(polylistGround2, "ground.obj", texture_names, 1.0, 0.0, 0.0, 55.0); // The skydome polylistSkydome = CreatePolylist(1000); createHemisphere(polylistSkydome, 100, 0, 0, 0, 1, 1, 1); for (i = 0; i < polylistSkydome->length; i++) polylistSkydome->items[i].texture_id = texture_names[4]; // Load the house and translate it, to put it next to the road polylistHouse = CreatePolylist(10); loadPolygonalObject(polylistHouse, "house.obj", texture_names, 1.0, object_positions[0].x, object_positions[0].y, object_positions[0].z); // A single tree object polylistTreeLeafs = CreatePolylist(10); //createSphere(polylistTreeLeafs, 0.7, 0.7, 0.7, 0, 1.7, 0, 0, 1, 0); for (i = 0; i < polylistTreeLeafs->length; i++) polylistTreeLeafs->items[i].texture_id = texture_names[0]; loadPolygonalObject(polylistTreeLeafs, "leaf.obj", texture_names, 1.0, 0.0, 1.8, 0.0); polylistTreeStem = CreatePolylist(10); createCylinder(polylistTreeStem, 0.075, 1.8, 0, 0, 0, 0.5, 0.3, 0); for (i = 0; i < polylistTreeStem->length; i++) polylistTreeStem->items[i].texture_id = texture_names[3]; // Done! printf("%d polygons\n", polylistHouse->length + polylistTreeLeafs->length + polylistTreeStem->length + polylistGround1->length + polylistGround2->length); }
void draw(Joint* temp) { glPushMatrix(); glTranslatef(temp->trans.x, temp->trans.y, temp->trans.z); if (temp->rotAxis.x == 1.0) { glRotatef(temp->rot.x, 1.0, 0.0, 0.0); } if (temp->rotAxis.y == 1.0) { glRotatef(temp->rot.y, 0.0, 1.0, 0.0); } if (temp->rotAxis.z == 1.0) { glRotatef(temp->rot.z, 0.0, 0.0, 1.0); } glPushMatrix(); glScalef(temp->scale.x, temp->scale.y, temp->scale.z); if (temp->shapeType.compare("cube") == 0) { glutSolidCube(1.0); } if (temp->shapeType.compare("sphere") == 0) { glutSolidSphere(1.0, 100, 100); } if (temp->shapeType.compare("cone") == 0) { glPushMatrix(); glRotatef(-90, 0.0, 1.0, 0.0); glutSolidCone(1.0,1.0, 100, 100); glPopMatrix(); } if (temp->shapeType.compare("cylinder") == 0) { createCylinder(); } glPopMatrix(); if (temp->child != NULL) { draw(temp->child); } glPopMatrix(); }
void draw(Element* temp) { glPushMatrix(); glTranslatef(temp->trans.x, temp->trans.y, temp->trans.z); if (temp == root) { glRotatef(temp->GlobalRot.x, 1.0, 0.0, 0.0); glRotatef(temp->GlobalRot.y, 0.0, 1.0, 0.0); glRotatef(temp->GlobalRot.z, 0.0, 0.0, 1.0); } glPushMatrix(); glScalef(temp->scale.x, temp->scale.y, temp->scale.z); if (temp->shapeType.compare("cube") == 0) { glutSolidCube(1.0); } if (temp->shapeType.compare("sphere") == 0) { glutSolidSphere(1.0, 100, 100); } if (temp->shapeType.compare("cone") == 0) { glPushMatrix(); glRotatef(-90, 0.0, 1.0, 0.0); glutSolidCone(1.0,1.0, 100, 100); glPopMatrix(); } if (temp->shapeType.compare("cylinder") == 0) { createCylinder(); } glPopMatrix(); if ((temp->child != NULL) && (temp != root)) { draw(temp->child); } if (temp == root) { for (int i = 0; i < root->rootChildren.size(); i++) { draw(root->rootChildren[i]); } } glPopMatrix(); }
void GLWidget::createAxis3D(int quality) { // middle point (sphere) createSphere(0.1f, quality, quality); axisSphereSize = sphereVerticesSize; axisSphereBuffer.create(); axisSphereBuffer.bind(); axisSphereBuffer.allocate(sphereVertices, axisSphereSize * sizeof(float)); axisBottomSphereSize = sphereConeSize; axisBottomSphereBuffer.create(); axisBottomSphereBuffer.bind(); axisBottomSphereBuffer.allocate(downSphereCone, axisBottomSphereSize * sizeof(float)); freeSphere(); //axis createCylinder(0.05f, 0.05f, 0.5f, quality); axisCylynderSize = cylinderSize; axisCylynderBuffer.create(); axisCylynderBuffer.bind(); axisCylynderBuffer.allocate(cylinderVertices, axisCylynderSize * sizeof(float)); freeCylinder(); createDisk(0.1f, quality); axisDiskSize = diskSize; axisDiskBuffer.create(); axisDiskBuffer.bind(); axisDiskBuffer.allocate(diskVertices, axisDiskSize * sizeof(float)); freeDisk(); createCone(0.1, 0.3, quality); axisConeSize = coneSize; axisConeBuffer.create(); axisConeBuffer.bind(); axisConeBuffer.allocate(coneVertices, axisConeSize * sizeof(float)); freeCone(); }
void initialise() { glClearColor(0.0f, 1.0f, 1.0f, 1.0f); projection = glm::perspective(20.0f, 800.0f/600.0f, 0.1f, 10000.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_VERTEX_ARRAY); s = new shader("phong"); if (!s->shaders[0] || !s->shaders[1] || !s->program) exit(EXIT_FAILURE); light.ambient = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); light.diffuse = glm::vec4(1.0f, 1.0f, 0.0f, 1.0f); light.specular = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); //object.geometry = createTorus(6, 50, 50); object.geometry = createCylinder(100,100); object.material = new material(); object.material->ambient = glm::vec4(0.5f, 0.25f, 0.15f, 1.0f); object.material->diffuse = glm::vec4(0.5f, 0.25f, 0.15f, 1.0f); object.material->specular = glm::vec4(0.5f, 0.25f, 0.15f, 1.0f); object.material->shininess = 1.5f; object.transform.position = glm::vec3(0.0f, 0.5f, 0.0f); }
void makeEntites() { sphereModel = createSphere(shader1, 0, 30, 30, 1.0f); cylinderModel = createCylinder(shader1, 0, 30, 2.0f, 1.0f, 1.0f); legLeft = Entity(Vector3(0, -1.5, 0), cylinderModel); legRight = Entity(Vector3(0, -1.5, 0), cylinderModel); kneeLeft = Entity(Vector3(0, -1.5, 0), sphereModel); kneeRight = Entity(Vector3(0, -1.5, 0), sphereModel); thighLeft = Entity(Vector3(-.5, -1.5, 0), cylinderModel); thighRight = Entity(Vector3(.5, -1.5, 0), cylinderModel); cylinder1 = Entity(Vector3(0, 0, 0), cylinderModel); cylinder1.setScale(.2, .2, .2); thighLeft.setScale(.4, .4, .4); thighRight.setScale(.4, .4, .4); cylinder1.addChild(&thighLeft); cylinder1.addChild(&thighRight); thighLeft.addChild(&kneeLeft); thighRight.addChild(&kneeRight); kneeLeft.addChild(&legLeft); kneeRight.addChild(&legRight); skybox = new Skybox(skyboxShader, images["skybox"]); wallModel = createCube(wallShader, images["cubeTexture"]); enemyModel = createCube(wallShader, images["slimeTexture"]); floorModel = createCube(wallShader, images["cubeTexture2"]); flagModel = createCube(wallShader, images["flagTexture"]); saveFlag = new Entity(Vector3(0,0,0), flagModel); saveFlag->setScale(.2, 5, .2); levels[currLevel]->initLevel(wallModel, floorModel); Title = new Text(textShader, images["font1"], 30, 35); Title->setPosition(Vector3(-220, 120, 0)); PlayBut = new Text(textShader, images["font1"], 20,25); PlayBut->setPosition(Vector3(-210, 20, 0)); ControlsBut = new Text(textShader, images["font1"], 20, 25); ControlsBut->setPosition(Vector3(-210, -10, 0)); notice = new Text(textShader, images["font1"], 15, 20); CreditsBut = new Text(textShader, images["font1"], 20, 25); CreditsBut->setPosition(Vector3(-210, -40, 0)); Exitbut = new Text(textShader, images["font1"], 20, 25); Exitbut->setPosition(Vector3(-210, -70, 0)); Restartbut = new Text(textShader, images["font1"], 20, 25); Restartbut->setPosition(Vector3(-210, -100, 0)); Paused = new Text(textShader, images["font1"], 20, 25); Paused->setColor(Color(1, 0, 0,1)); Back = new Text(textShader, images["font1"], 20, 25); Back->setColor(Color(1, 1, 0, 1)); Credits1 = new Text(textShader, images["font1"], 20, 25); Credits1->setPosition(Vector3(-250, 50, 0)); time = new Text(textShader, images["font1"], 20, 25); Credits2 = new Text(textShader, images["font1"], 20, 25); Credits2->setPosition(Vector3(-270, 0, 0)); Controls1 = new Text(textShader, images["font1"], 15, 20); Controls1->setPosition(Vector3(-250, 120, 0)); Controls2 = new Text(textShader, images["font1"], 15, 20); Controls2->setPosition(Vector3(-250, 60, 0)); Controls3 = new Text(textShader, images["font1"], 15, 20); Controls3->setPosition(Vector3(-250, 0, 0)); Controls4 = new Text(textShader, images["font1"], 15, 20); Controls4->setPosition(Vector3(-250, -60, 0)); Controls5 = new Text(textShader, images["font1"], 15, 20); Controls5->setPosition(Vector3(-250, -120, 0)); Controls6 = new Text(textShader, images["font1"], 15, 20); Controls6->setPosition(Vector3(-250, -180, 0)); Loading = new Text(textShader, images["font1"], 15, 20); Loading->setPosition(Vector3(-60, 120, 0)); for (int i = 0; i < 30; i++){ enemies[i] = new Enemy(Vector3(0,-.5,0),enemyModel); enemies[i]->setScale(3,.5,3); } }
iPhysicsCollision* iPhysics::createCylinder(float32 radius, float32 height, const iaMatrixf& offset) { return createCylinder(radius, height, offset, _shadowWorldID); }