void updateCamera() { // update orientation mat4 cameraTransform(1); //cameraTransform = rotate(cameraTransform, alpha, vec3(0,1,0)); // pass this information to cuda wrapper //cameraTransform = rotate(cameraTransform, beta, vec3(1,0,0)); vec4 pos4 = (cameraTransform * vec4(cam->position, 1.0)); vec4 up4 = (cameraTransform * vec4(cam->up, 0.0)); vec4 viewDir4 = (cameraTransform * vec4(0,0,-1, 0.0)); cam->position = vec3(pos4.x, pos4.y, pos4.z); cam->up = vec3(up4.x, up4.y, up4.z); viewDir = vec3(viewDir4.x, viewDir4.y, viewDir4.z); mat4 view = glm::lookAt(cam->position, cam->position + viewDir, cam->up); // LOOK: Center is now position + view direction //mat4 view = glm::lookAt(cam->position, cam->position + viewDir, cam->up); // LOOK: Center is now position + view direction cam->view = view; if (alpha != 0) printf("alpha = %f\n", alpha); if (beta != 0) printf("beta = %f\n", beta); //alpha = 0; // commented this out because now alpha and beta are cumulative and are passed to cuda side to modify the model matrix //beta = 0; zTranslateDistance = 0; }
void drawScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); cameraTransform(&svCtx.camera); if(svCtx.drawHandler != NULL) svCtx.drawHandler(); drawCameraOrientationWidget(&svCtx.camWidget); glFlush(); glutSwapBuffers(); }
void PCamera::fromLight(const PDirectionalLight *light, const PBox *bbox) { PVector3 center = pVector3(0, 0, 0); PVector3 eye = light->direction() * 100.0f; // any point on the light ray is OK. PVector3 up; PVector3 lightSource = pVector3(-light->direction()[0], -light->direction()[1], -light->direction()[2]); if (lightSource[1] >= 0) { if (lightSource[1] < 0.99f) { up = pVector3(0, 1, 0); } else { up = pVector3(-1.0f, 0.0f, 0.0f); } } else { if (lightSource[1] > -0.99f) { up = pVector3(0, -1, 0); } else { up = pVector3(-1.0f, 0.0f, 0.0f); } } up.normalize(); // Generate the camera matrix m_localTransform.setLookAt(eye[0], eye[1], eye[2], center[0], center[1], center[2], up[0], up[1], up[2]); PBox bboxInCameraSpace(*bbox); bboxInCameraSpace.transform(cameraTransform()); // Generate the projection matrix m_projection.orthogonal(bboxInCameraSpace.min()[0], bboxInCameraSpace.max()[0], bboxInCameraSpace.min()[1], bboxInCameraSpace.max()[1], bboxInCameraSpace.min()[2] - 0.01f, bboxInCameraSpace.max()[2] + 0.01f); }
void renderScene(){ // Clear framebuffer & depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClearColor(1.0,1.0,1.0,1.0); //I actually need to call it only once, so if i put it in setupscene is ok cameraTransform(); glDisable(GL_LIGHTING); drawAxes(); drawGrid(); //fog(); //cubeWorld(); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEnable(GL_LIGHTING); //Enable global lighting ////WITH = All the light will NOT move with the camera (light fixed even if i rotate) ////Because i tell at every frame to fix the light at those 2 points glLightfv(GL_LIGHT0, GL_POSITION, left_light_position); glLightfv(GL_LIGHT1, GL_POSITION, right_light_position); /*setMaterial(jade); glutSolidCube(2);*/ //setMaterial(ruby); //doesn't work without glDisable(GL_COLOR_MATERIAL); /*for(int i=0; i<cube1.normals.size();i++) std::cout << cube1.worldNormals.at(i) << std::endl; std::cout<<"ayee"<<std::endl<<std::endl<<std::endl;*/ for (int i = 0 ; i<collection.size(); i++) collection.at(i).draw(Vector(0.3f,0.15f,0.15f)); //Vector(102,51,51) glutSwapBuffers(); }
void renderScene(){ // Clear framebuffer & depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //where should the camera look at? cameraTransform(); glDisable(GL_LIGHTING);//disable lighting not to affect the drawings of meta-objects drawAxes(); drawGrid(); glEnable(GL_LIGHTING);//resume lighting //WITH = All the light will NOT move with the camera (light fixed even if i rotate) //Because i tell at every frame to fix the light at those 2 points glLightfv(GL_LIGHT0, GL_POSITION, left_light_position); glLightfv(GL_LIGHT1, GL_POSITION, right_light_position); glColor3f(0.5,0.5,0.5); field.getCollisionPlane().draw(Vector3f(0.93, 0.82, 0)); //WTF only certain colors work. JK it's because number must be float.. then why tf there are some 255 every now and then (e.g. axes) glPushMatrix(); glTranslatef(field.getBlackHoleCentre().x,field.getBlackHoleCentre().y,field.getBlackHoleCentre().z); glColor3f(0.7,0.5,0); glutSolidSphere(0.1f,4,4); glPopMatrix(); field.draw(); //TODO pause button field.update(); glutSwapBuffers(); }