void RenderPanel::setViewController( ViewController* controller ) { view_controller_ = controller; if( view_controller_ ) { setCamera( view_controller_->getCamera() ); view_controller_->activate(); } else { setCamera( NULL ); } }
//============================================================================== // //------------------------------------------------------------------------------ void Camera::setCamera(CameraBace* moveToCamera,int frame) { //if(_moveToCamera != nullptr) return; if(frame == 0) { setCamera(moveToCamera); return; } _moveToCamera = moveToCamera; _maxFrame = frame; _nowFrame = 0; memcpy(_destCamera,_currentCam,sizeof(CameraBace)); memcpy(_defaultCam,_currentCam,sizeof(CameraBace)); setCamera(_defaultCam); }
void Camera::renderCubeMap(VisualizationParameterSet& visParams) { // cube map has only to be build if a reflective object is chosen if(!graphicsManager->doEnvRendering()) return; // set clear color once Surface* backgroundSurface = simulation->getBackgroundSurface(); glClearColor(backgroundSurface->color[0], backgroundSurface->color[1], backgroundSurface->color[2], backgroundSurface->color[3]); // cube map rendering for(int generateCubeMap = 6; generateCubeMap > 0; generateCubeMap--) { glClear(default_clear); graphicsManager->setCubeMapPerspective(); setCamera(visParams, generateCubeMap); graphicsManager->updateLights(true, false, visParams.provideUniforms); graphicsManager->renderEnvironment(maxRange); // prepare surface properties glCallList(graphicsManager->enableStateDL[visParams.surfaceStyle]); rootNode->draw(visParams); glCallList(graphicsManager->disableStateDL[visParams.surfaceStyle]); graphicsManager->revertLightTextureUnits(visParams.provideUniforms); glFlush(); // save image to cubemap file graphicsManager->handleCubeMapping(generateCubeMap, simulation->getFilename()); } }
void keyboard(unsigned char k, int x, int y) { switch (k) { case 27: exit(0); } setCamera(); }
void Camera::rotateCamera(int i){ float ang = 3.0*i; AngleAxis<float> a((ang*M_PI)/180.0, Vector3f::UnitY() ); Matrix3f m; Vector3f v1, v2, v3; Vector3f eyeOld; float dist; eyeOld = eye; // Define axis of rotation m = AngleAxisf((0.0*M_PI)/180.0, Vector3f::UnitX()) * AngleAxisf((ang*M_PI)/180.0, Vector3f::UnitY()) * AngleAxisf((0.0*M_PI)/180.0, Vector3f::UnitZ()); // Find vector from eye to aim and use as rotation point around origin v1 << aim - eye; dist = v1.norm(); // Rotate point and find vector between the original point and the rotated point v2 << v1; v2 << m * v2; v2 << v2 - v1; // Apply the difference to the eye v3 << eye + v2; v3 << v3 - aim; v3.normalize(); eye << dist * v3 + aim; eye(1) = eyeOld(1); setCamera(); }
void ::CameraContral::riseCameraTo(float h) { mHeight = h; mHeight = (mHeight > 100.0f)? 100.0f: mHeight; mHeight = (mHeight < 10.0f)? 10.0f: mHeight; setCamera(); }
bool CameraSystem::readFromDirectory(const std::string& directory) { if (!boost::filesystem::is_directory(directory)) { return false; } // read extrinsic data boost::filesystem::path extrinsicPath(directory); extrinsicPath /= "camera_system_extrinsics.txt"; std::vector<std::string> cameraNames; readFromTextFile(extrinsicPath.string(), cameraNames); // read intrinsic data for (size_t i = 0; i < cameraNames.size(); ++i) { boost::filesystem::path calibPath(directory); calibPath /= cameraNames.at(i) + "_camera_calib.yaml"; CameraPtr camera = CameraFactory::instance()->generateCameraFromYamlFile(calibPath.string()); if (!camera) { return false; } setCamera(i, camera); } return true; }
void CameraManager::updateCurrent_(float dt) { glm::vec3 dx = target_ - current_; glm::vec3 maxV(getParam("camera.maxVx"), getParam("camera.maxVy"), getParam("camera.maxVz")); // If we're trying to move faster than we're allowed, // clip our velocity in that direction. if (fabs(dx.x) > maxV.x * dt) { dx.x = dx.x < 0 ? -1 * maxV.x * dt : maxV.x * dt; } if (fabs(dx.y) > maxV.y * dt) { dx.y = dx.y < 0 ? -1 * maxV.y * dt : maxV.y * dt; } if (fabs(dx.z) > maxV.z * dt) { dx.z = dx.z < 0 ? -1 * maxV.z * dt : maxV.z * dt; } current_ = current_ + dx; setCamera(current_); }
bool BattleScene::init() { Layer::init(); currentLayer = this; Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB565); setCamera(); controlCamera(); setCameraMask(2); createBackground(); enableTouch(); initUILayer(); GameMaster::create(); MessageDispatchCenter::getInstance()->registerMessage(MessageType::BLOOD_MINUS, [](Actor * heroActor) { uiLayer->bloodDrop(heroActor); }); MessageDispatchCenter::getInstance()->registerMessage(MessageType::ANGRY_CHANGE, [](Actor * heroActor) { uiLayer->angryChange(heroActor); }); scheduleUpdate(); return true; }
void SceneWindow::switchToDefaultCamera() { Camera* camera = mainCamera.get(); if( !camera ) return; setCamera(camera); }
/* Function: cameraOrbit * Description: Rotates the entire camera about a point using the mouse. * Input: x - X Coordinate of the mouse * y - Y Coordinate of the mouse * Output: None */ void cameraOrbit(int x, int y) { point mouse; mouse.x = x - mousePos.x; mouse.y = y - mousePos.y; Phi += mouse.x * 0.01; Theta += mouse.y * 0.01; if (Phi > (2 * PI)) Phi -= 2 * PI; if (Phi < 0) Phi += 2 * PI; if (Theta > (PI / 2 - 0.01)) // dont let the point enter the north pole Theta = PI / 2 - 0.01; if (Theta < (-PI / 2 + 0.01)) Theta = -PI / 2 + 0.01; // Recompute camera position cameraPos.x = lineOfSight.x + (R * cos(Phi) * cos(Theta)); cameraPos.y = lineOfSight.y + (R * sin(Theta)); cameraPos.z = lineOfSight.z + (-R * sin(Phi) * cos(Theta)); setCamera(); } //end cameraOrbit
void onDisplay () /* pre: glut window needs to be refreshed post: model is drawn */ { /* clears requested bits (color and depth) in glut window */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //if(wireframe)glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // else glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); /* draw entire scene into cleared window */ glPushMatrix(); setCamera(); Display(); glPopMatrix(); /* check for any errors when rendering */ GLenum errorCode = glGetError(); if (errorCode == GL_NO_ERROR) { /* double-buffering - swap the back and front buffers */ glFlush(); glutSwapBuffers(); } else { ReportError(errorCode); } }
Camera::Camera(const Vector2f &worldMax, const Vector2f &screenMax) { setCamera(Vector2f::ZERO, worldMax, Vector2f::ZERO, screenMax, Vector2f::ZERO, worldMax); }
/** Callback that occurs when glut thinks its time to redraw the window. */ void handleDisplay() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // update the light position glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); setCamera(); // draw the light source drawLightSource(); // draw the wall background drawBackdropGeometry(); // draw scene objects glColor3f(0.0,0.0,1.0); drawScene(); // calc and draw shadows if (shadowsOn && light0On) { calculateShadows(floorPlane); drawShadows(); calculateShadows(wallPlane); drawShadows(); } glFlush(); glutSwapBuffers(); }
/////////////////////////////////////////////////////////////////////////////// // initialize OpenGL states and scene /////////////////////////////////////////////////////////////////////////////// void ModelGL::init() { glShadeModel(GL_SMOOTH); // shading mathod: GL_SMOOTH or GL_FLAT glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment // enable /disable features glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); //glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); glEnable(GL_BLEND); // track material ambient and diffuse from surface color, call it before glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); //glEnable(GL_COLOR_MATERIAL); glClearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]); // background color glClearStencil(0); // clear stencil buffer glClearDepth(1.0f); // 0 is near, 1 is far glDepthFunc(GL_LEQUAL); initLights(); setCamera(0, 0, 8, 0, 0, 0); listId = createEarthDL(); }
TexturePtr LinearGradient::createAsTexture(int width, int height) { const float w = static_cast<float>(width); const float h = static_cast<float>(height); const float sa = std::abs(std::sin(-angle_ / 180.0f * static_cast<float>(M_PI))); const float ca = std::abs(std::cos(-angle_ / 180.0f * static_cast<float>(M_PI))); //const float length = std::min(ca < FLT_EPSILON ? FLT_MAX : width / ca, sa < FLT_EPSILON ? FLT_MAX : height / sa); //const float length = std::min(ca < FLT_EPSILON ? w : 2.0f * ca * w, sa < FLT_EPSILON ? h : 2.0f * sa * h); WindowPtr wnd = WindowManager::getMainWindow(); CameraPtr cam = std::make_shared<Camera>("ortho_lg", 0, width, 0, height); auto grad = createRenderable(); grad->setCamera(cam); grad->setScale(ca < FLT_EPSILON ? w : 2.0f * w / ca, sa < FLT_EPSILON ? h : 2.0f * h / sa); grad->setPosition(w/2.0f, h/2.0f); RenderTargetPtr rt = RenderTarget::create(width, height); rt->getTexture()->setFiltering(-1, Texture::Filtering::LINEAR, Texture::Filtering::LINEAR, Texture::Filtering::POINT); rt->getTexture()->setAddressModes(-1, Texture::AddressMode::CLAMP, Texture::AddressMode::CLAMP); rt->setCentre(Blittable::Centre::TOP_LEFT); rt->setClearColor(Color(0,0,0,0)); { RenderTarget::RenderScope rs(rt, rect(0, 0, width, height)); grad->preRender(wnd); wnd->render(grad.get()); } return rt->getTexture(); }
void renderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setCamera(10,2,10,0,2,-5); glUseProgram(p); setUniforms(); //glBindVertexArray(vao[0]); glBindBuffer(GL_ARRAY_BUFFER, vbos[0]); glVertexAttribPointer(vertexLoc, 4, GL_FLOAT, 0, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, vbos[1]); glVertexAttribPointer(colorLoc, 4, GL_FLOAT, 0, 0, 0); glDrawArrays(GL_TRIANGLES, 0, 3); //glBindVertexArray(vao[1]); glBindBuffer(GL_ARRAY_BUFFER, vbos[2]); glVertexAttribPointer(vertexLoc, 4, GL_FLOAT, 0, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, vbos[3]); glVertexAttribPointer(colorLoc, 4, GL_FLOAT, 0, 0, 0); glDrawArrays(GL_TRIANGLES, 0, 3); //glBindVertexArray(vao[2]); glBindBuffer(GL_ARRAY_BUFFER, vbos[4]); glVertexAttribPointer(vertexLoc, 4, GL_FLOAT, 0, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, vbos[5]); glVertexAttribPointer(colorLoc, 4, GL_FLOAT, 0, 0, 0); glDrawArrays(GL_LINES, 0, 6); glutSwapBuffers(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); setCamera(); /*material(slate); glPushMatrix(); glTranslated(0, 0, -40); desenhaSolo(); glPopMatrix();*/ //desenhaEixos(); desenhaLabirinto(); if(estado.eixoTranslaccao) { cout << "Translate... " << estado.eixoTranslaccao << endl; } glFlush(); glutSwapBuffers(); }
int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(800,800); glutInitWindowPosition(10,10); glutCreateWindow("Super Ellipsoid"); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutSpecialFunc(specialKeyboard); glutMouseFunc(mouse); glutMotionFunc(mouseMotion); glutIdleFunc(idle); glutCreateMenu(displayMenu); glutAddMenuEntry("Increase m",1); glutAddMenuEntry("Decrease m",2); glutAddMenuEntry("Increase n",3); glutAddMenuEntry("Decrease n",4); glutAddMenuEntry("Exit",5); glutAttachMenu(GLUT_RIGHT_BUTTON); installShaders(); setCamera(); matrixIdentity(Projection); matrixPerspective(Projection, 40, 1.0, (GLfloat) 1, 750); initValues(); glClearColor(0.0,0.0,0.0,1.0); glutMainLoop(); return 0; }
void display(void) { ++FrameCount; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); eye=Vec3( dist * cos( theta ) * (cos( phi )), dist * sin( theta ) * (cos( phi )), dist * sin( phi ) ); setLighting(); setCamera(); float EYE[]={eye.x,eye.y,eye.z}; glUseProgram(ProgramID); glUniformMatrix4fv(projMatrixLoc, 1, false, projMatrix); glUniformMatrix4fv(viewMatrixLoc, 1, false, viewMatrix); glUniform4fv(LightPosLoc, 1, LightPosition); glUniform4fv(LightDifLoc, 1, DiffuseLight); glUniform4fv(LightAmbLoc, 1, AmbientLight); glUniform4fv(LightSpecLoc, 1, SpecularLight); glUniform3fv(eyeLoc, 1, EYE); glBindVertexArray(VAO); if(MODE==0){ glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glDrawElements(GL_TRIANGLES,3*model->nf,GL_UNSIGNED_INT,(GLvoid*)0); } else if(MODE==1){ glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glDrawElements(GL_TRIANGLES,3*model->nf,GL_UNSIGNED_INT,(GLvoid*)0); } else if(MODE==2){ glUniform3f(cLoc,0,0,0); glDrawElements(GL_POINTS,3*model->nf,GL_UNSIGNED_INT,(GLvoid*)0); } glutSwapBuffers(); }
SceneView::SceneView( osg::DisplaySettings* ds) { _displaySettings = ds; _lightingMode=NO_SCENEVIEW_LIGHT; _prioritizeTextures = false; setCamera(new Camera); _camera->setViewport(new Viewport); _camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f)); _initCalled = false; _camera->setDrawBuffer(GL_BACK); _requiresFlush = true; _activeUniforms = DEFAULT_UNIFORMS; _previousFrameTime = 0; _previousSimulationTime = 0; _dynamicObjectCount = 0; }
void init(void) { //背景色 glClearColor(0.2, 0.2, 0.3, 1.0); setCamera();//視点を求める setLight(); //光源設定 glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); printf("マウス/キー操作の説明には'h'キーをプッシュ \n"); glGenTextures(2, texName);//テクスチャオブジェクトの名前付け //Terrainデータの作成 makeTerrainData(); Bitmap* bm0 = new Bitmap(); loadBitmap(bm0, "../../bmp/altgrad4.bmp"); makeTerrainImage(bm0); setTerrainTexture(0); //particle用テクスチャ Bitmap* bm1 = new Bitmap(); loadBitmap(bm1, "../../bmp/snow1.bmp"); makeParticleImage(bm1); setParticleTexture(1); //時間計測 lastTime = timeGetTime(); elapseTime1 = 0.0; elapseTime2 = 0.0; countP = 0.0; }
void keyboard(unsigned char key, int x, int y) { switch((unsigned char)key) { case 27://Esc exit(0); break; case 'w': if(flagWireframe) flagWireframe = false; else if(!flagWireframe) flagWireframe = true; break; case 'R'://reset(初期値に戻す) for(int i = 0; i < 3; i++) lightPos[i] = lightPos0[i]; view = view0; setCamera(); break; case 'l': sKey = LIGHT; break; case 'h': if(flagHelp) flagHelp = false; else flagHelp = true; break; default: break; } }
void keyboard(unsigned char key, int x, int y) { #define ESC 27 if (key == ESC) exit(0); else if(key == 'z'){ radius *= 1.05; setCamera(); glutPostRedisplay(); }else if(key == 'x'){ radius *= 0.95; setCamera(); glutPostRedisplay(); } }
void CameraContral::resetCamera() { mX = 0.0f; mY = 0.0f; mHeight = 75.0f; setCamera(); }
Camera::Camera(const QCameraInfo& camera_info, const QString& stylesheet, QWidget* parent) : OpenableWidget(parent) { commonConstructor(stylesheet); setCamera(camera_info); }
void Level::Impl::initSound() { auto sound = game->city()->statistic().services.find<city::AmbientSound>(); if( sound.isValid() ) sound->setCamera(renderer.camera()); }
void GLManager::initializeGL() { glClearColor(0,0,0,0); glShadeModel(GL_SMOOTH); glEnable(GL_TEXTURE_2D); // 载入所有星球的纹理 loadTextures(); //设置摄像机 setCamera(Point(10.0, 2.0, 10.0), Point(0.0, 0.0, 0.0)); //设置光照及材质 GLfloat mat_shininess [] = {50.0}; GLfloat light_position [] = {0,0,0,1}; GLfloat lmodel_ambient [] = {0.8,0.8,0.8,1.0}; glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); }
void init(void) { //背景色 glClearColor(0.2, 0.2, 0.3, 1.0); setCamera();//視点を求める setLight(); //光源設定 glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); printf("マウス/キー操作の説明には'h'キーをプッシュ \n"); //テクスチャの設定 setCubeMap(); //pet robot アニメーション pet.unitTime = 0.05;//1フレーム当たりの時間(最初は仮の値) //フレームデータを作成 pet.numFrame0 = 0; pet.vPos.x = 1.0; pet.vPos.z = -1.0; pet.vAng.y = -90.0; pet.numFrame0 = 0; frameCount = 0; pet.walk(2.0, 0.2, 1.0); pet.turn(180.0, 2.0); pet.walk(2.0, 0.2, 1.0); pet.turn(-180.0, 2.0); pet.walk(2.0, 0.2, 1.0); pet.turn(180, 2.0); pet.walk(2.0, 0.2, 1.0); pet.turn(-180.0, 2.0); printf("numFrame0=%d \n", pet.numFrame0); }
void init(void) { //背景色 glClearColor(0.2, 0.2, 0.3, 1.0); setCamera();//視点を求める setLight(); //光源設定 glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); printf("マウス/キー操作の説明には'h'キーをプッシュ \n"); //Terrainデータの作成 makeTerrainData(); Bitmap* bm0 = new Bitmap(); loadBitmap(bm0, "../../bmp/altgrad4.bmp"); makeTerrainImage(bm0); setTerrainTexture(); //particle countP = 0; fps = 0; elapseTime1 = 0.0;//1sec間以内の経過時間 elapseTime2 = 0.0; //init()後の総経過時間 for(int i = 0; i < NUM_PARTICLE; i++) p[i] = CParticle(); for(int i = 0; i < NUM_PARTICLE2; i++) q[i] = CParticle2(); frameCount = 0; }