void Update() { glLoadIdentity(); LookAt(); RotateCamera(ROLL, AngR); RotateCamera(YAW, AngY); RotateCamera(PITCH, AngP); }
void BulletOpenGLApplication::Special(int key, int x, int y) { // This function is called by FreeGLUT whenever special keys // are pressed down, like the arrow keys, or Insert, Delete etc. switch(key) { // the arrow keys rotate the camera up/down/left/right case GLUT_KEY_LEFT: RotateCamera(m_cameraYaw, +CAMERA_STEP_SIZE); break; case GLUT_KEY_RIGHT: RotateCamera(m_cameraYaw, -CAMERA_STEP_SIZE); break; case GLUT_KEY_UP: RotateCamera(m_cameraPitch, +CAMERA_STEP_SIZE); break; case GLUT_KEY_DOWN: RotateCamera(m_cameraPitch, -CAMERA_STEP_SIZE); break; } }
/** * Mouse active motion callback (when button is pressed) */ void MouseMotionCallback(int x, int y) { if (gPreviousMouseX >= 0 && gPreviousMouseY >= 0) { //compute delta float deltaX = x-gPreviousMouseX; float deltaY = y-gPreviousMouseY; gPreviousMouseX = x; gPreviousMouseY = y; //orbit, strafe, or zoom if (gMouseButton == GLUT_LEFT_BUTTON) { RotateCamera(deltaX, deltaY); } else if (gMouseButton == GLUT_MIDDLE_BUTTON) { StrafeCamera(deltaX, deltaY); } else if (gMouseButton == GLUT_RIGHT_BUTTON) { ZoomCamera(deltaY); } } else { gPreviousMouseX = x; gPreviousMouseY = y; } }
void WaterSimulation::Show(bool Enable) { if (Enable) RotateCamera(); else Cam->setRotation(0); HeightField_->setVisible(Enable); WaterPlane_->setVisible(Enable); }
void BumpMapping::Show(bool Enable) { if (Enable) RotateCamera(); else Cam->setRotation(0); Object_->setVisible(Enable); Object2_->setVisible(Enable); LightObj_->setVisible(Enable); }
/* Handle mouse motion */ void HandleMouseMotion(int x,int y) { static int xlast=-1,ylast=-1; int dx,dy; dx = x - xlast; dy = y - ylast; if (dx < 0) dx = -1; else if (dx > 0) dx = 1; if (dy < 0) dy = -1; else if (dy > 0) dy = 1; if (currentbutton == GLUT_LEFT_BUTTON) RotateCamera(-dx,dy,0); else if (currentbutton == GLUT_MIDDLE_BUTTON) RotateCamera(0,0,dx); xlast = x; ylast = y; }
/* Deal with special key strokes */ void HandleSpecialKeyboard(int key,int x, int y) { switch (key) { case GLUT_KEY_LEFT: RotateCamera(-1,0,0); break; case GLUT_KEY_RIGHT: RotateCamera(1,0,0); break; case GLUT_KEY_UP: RotateCamera(0,1,0); break; case GLUT_KEY_DOWN: RotateCamera(0,-1,0); break; case GLUT_KEY_F1: break; case GLUT_KEY_F2: break; } }
void CameraMover::Update() { if (input::TouchCount(0) == 1) { RotateCamera(); } else if (input::TouchCount(0) > 1) { if (input::GetTouch(0, 0)->phase == input::TouchPhaseBegan) { forward = !forward; } MoveCamera(forward ? -1 : 1); } }
void UpdateCamera(Camera* camera) override { switch (_mode) { case Mode::rotate: { RotateCamera(camera); } break; case Mode::zoom: ZoomCamera(camera); break; default: break; } }
static void MotionCallback(int x, int y) { if(!TwEventMouseMotionGLUT(x, y)) { if(gButton==2) { int dx = gMouseX - x; int dy = gMouseY - y; RotateCamera(dx, dy); gMouseX = x; gMouseY = y; } else gCollisionTests[gTest]->MotionCallback(x, y); } }
void WaterSimulation::Update() { WaterPlane_->getMeshBuffer(0)->textureTranslate(0, dim::point2df(0, 0.005f)); WaterPlane_->getMeshBuffer(0)->textureTranslate(1, dim::point2df(0, 0.005f)); if (spControl->keyDown(io::KEY_UP)) WaterPlane_->translate(dim::vector3df(0, 0.01f, 0)); if (spControl->keyDown(io::KEY_DOWN)) WaterPlane_->translate(dim::vector3df(0, -0.01f, 0)); ShdPixel_->setConstant("ScreenWidth", ScrWidth); ShdPixel_->setConstant("ScreenHeight", ScrHeight); ShdPixel_->setConstant("IsUnderWater", false); ShdPixel_->setConstant("WaterPlaneHeight", WaterPlane_->getPosition().Y); ShdPixel_->setConstant("ObjectHeight", HeightField_->getScale().Y); TurnLight(); RotateCamera(); }
/* Deal with plain key strokes */ void HandleKeyboard(unsigned char key,int x, int y) { switch (key) { case ESC: /* Quit */ case 'Q': case 'q': exit(0); break; case 'h': /* Go home */ case 'H': CameraHome(0); break; case '[': /* Roll anti clockwise */ RotateCamera(0,0,-1); break; case ']': /* Roll clockwise */ RotateCamera(0,0,1); break; case 'i': /* Translate camera up */ case 'I': TranslateCamera(0,1); break; case 'k': /* Translate camera down */ case 'K': TranslateCamera(0,-1); break; case 'j': /* Translate camera left */ case 'J': TranslateCamera(-1,0); break; case 'l': /* Translate camera right */ case 'L': TranslateCamera(1,0); break; case '=': case '+': FlyCamera(1); break; case '-': case '_': FlyCamera(-1); break; case 'w': /* Write the image to disk */ case 'W': windowdump = !windowdump; break; case 'r': case 'R': record = !record; break; case '<': case ',': iterationdepth--; if (iterationdepth < 0) iterationdepth = 0; geometrydirty = REALDIRTY; break; case '>': case '.': iterationdepth++; geometrydirty = REALDIRTY; break; } }
int CObject::UpdateControl (void) { switch (info.controlType) { case CT_NONE: break; case CT_FLYING: ReadFlyingControls (this); break; case CT_REPAIRCEN: Int3 (); // -- hey!these are no longer supported!!-- do_repair_sequence (this); break; case CT_POWERUP: DoPowerupFrame (); break; case CT_MORPH: //morph implies AI DoMorphFrame (); //NOTE: FALLS INTO AI HERE!!!! case CT_AI: //NOTE LINK TO CT_MORPH ABOVE!!! if (gameStates.gameplay.bNoBotAI || (gameStates.app.bGameSuspended & SUSP_ROBOTS)) { mType.physInfo.velocity.SetZero (); mType.physInfo.thrust.SetZero (); mType.physInfo.rotThrust.SetZero (); DoAnyRobotDyingFrame (this); #if 1//ndef _DEBUG return 1; #endif } else if (USE_D1_AI) DoD1AIFrame (this); else DoAIFrame (this); break; case CT_CAMERA: RotateCamera (); break; case CT_WEAPON: LaserDoWeaponSequence (this); break; case CT_EXPLOSION: DoExplosionSequence (); break; case CT_SLEW: break; //ignore case CT_DEBRIS: DoDebrisFrame (this); break; case CT_LIGHT: break; //doesn't do anything case CT_REMOTE: break; //movement is handled in com_process_input case CT_CNTRLCEN: if (gameStates.gameplay.bNoBotAI) return 1; DoReactorFrame (this); break; default: Error ("Unknown control nType %d in CObject %i, sig/nType/id = %i/%i/%i", info.controlType, OBJ_IDX (this), info.nSignature, info.nType, info.nId); } return 0; }
void CNuGenDimensionView::OnMouseMove(UINT nFlags, CPoint point) { CChildFrame* pFrame = static_cast<CChildFrame*>(GetParentFrame()); SetFocus(); if (!pFrame->m_commander) { switch (m_hand_action ) { case HA_ROTATE: if (nFlags & MK_LBUTTON) { SG_VECTOR downPnt; SG_VECTOR curPnt; // Convert the mouse left button down position to world m_Camera.GetWorldCoord(m_ScreenLeftButtonDownPoint.x, m_ScreenLeftButtonDownPoint.y, 0.0, downPnt); // Convert the mouse point into world coordinates m_Camera.GetWorldCoord(point.x, point.y, 0.0,curPnt); //VecSubf(curPnt, downPnt, curPnt); curPnt = sgSpaceMath::VectorsSub(curPnt, downPnt); CSize deltaPos; deltaPos = m_ScreenLeftButtonDownPoint - point; m_ScreenLeftButtonDownPoint = point; RotateCamera(deltaPos); Invalidate(FALSE); } break; case HA_MOVE: if (nFlags & MK_LBUTTON) { SG_VECTOR downPnt; SG_VECTOR curPnt; // Convert the mouse left button down position to world m_Camera.GetWorldCoord(m_ScreenLeftButtonDownPoint.x, m_ScreenLeftButtonDownPoint.y, 0.0, downPnt); // Convert the mouse point into world coordinates m_Camera.GetWorldCoord(point.x, point.y, 0.0,curPnt); //VecSubf(curPnt, downPnt, curPnt); curPnt = sgSpaceMath::VectorsSub(curPnt, downPnt); m_ScreenLeftButtonDownPoint = point; TranslateCamera(curPnt); Invalidate(FALSE); } break; case HA_ZOOM: if (nFlags & MK_LBUTTON) { SG_VECTOR downPnt; SG_VECTOR curPnt; // Convert the mouse left button down position to world m_Camera.GetWorldCoord(m_ScreenLeftButtonDownPoint.x, m_ScreenLeftButtonDownPoint.y, 0.0, downPnt); // Convert the mouse point into world coordinates m_Camera.GetWorldCoord(point.x, point.y, 0.0,curPnt); //VecSubf(curPnt, downPnt, curPnt); curPnt = sgSpaceMath::VectorsSub(curPnt, downPnt); CSize deltaPos; deltaPos = m_ScreenLeftButtonDownPoint - point; m_ScreenLeftButtonDownPoint = point; ZoomCamera(deltaPos); Invalidate(FALSE); } break; default: break; } } if (!pFrame->m_commander) /*pFrame->m_commander->MouseMove(nFlags,point.x,point.y); else*/ if (!(nFlags & MK_LBUTTON)) { int snapSz = pFrame->GetSnapSize(); const sgCObject* oldHotObj = Drawer::CurrentHotObject; Drawer::CurrentHotObject = GetTopObject(GetHitsInRect(CRect(point.x-snapSz, point.y-snapSz, point.x+snapSz, point.y+snapSz),true)); Drawer::TopParentOfHotObject = GetObjectTopParent(Drawer::CurrentHotObject); if (Drawer::TopParentOfHotObject) Drawer::CurrentHotObject = Drawer::TopParentOfHotObject; /**************************************/ if (Drawer::CurrentHotObject && (Drawer::CurrentHotObject->GetType()==SG_OT_LINE || Drawer::CurrentHotObject->GetType()==SG_OT_CIRCLE || Drawer::CurrentHotObject->GetType()==SG_OT_SPLINE || Drawer::CurrentHotObject->GetType()==SG_OT_ARC || Drawer::CurrentHotObject->GetType()==SG_OT_CONTOUR) ) { sgC2DObject* spl = reinterpret_cast<sgC2DObject*>(Drawer::CurrentHotObject); CString messs = "2DObject "; if (spl->IsClosed()) messs += " Closed; "; else messs += " No closed; "; if (spl->IsLinear()) { messs += " Linear;"; } else { messs += " No linear - "; SG_VECTOR plN; double plD; if (spl->IsPlane(&plN,&plD)) { CString aaaa; aaaa.Format("Normal: X=%f,Y=%f,Z=%f D: %f",plN.x,plN.y,plN.z,plD); messs += " Plane; "; messs+=aaaa; } else messs += " No Plane; "; } if (spl->IsSelfIntersecting()) messs += "Self intersecing; "; else messs += "No Self intersecing; "; pFrame->PutMessage(IApplicationInterface::MT_MESSAGE, messs); } else if (Drawer::CurrentHotObject && (Drawer::CurrentHotObject->GetType()==SG_OT_3D)) { sgC3DObject* ddd = reinterpret_cast<sgC3DObject*>(Drawer::CurrentHotObject); CString messs; messs.Format("Volume = %f",ddd->GetVolume()); messs+=" Square = "; CString aaaa; aaaa.Format("%f",ddd->GetSquare()); messs+=aaaa; pFrame->PutMessage(IApplicationInterface::MT_MESSAGE, messs); } else pFrame->PutMessage(IApplicationInterface::MT_MESSAGE, " "); /**************************************/ if (oldHotObj!=Drawer::CurrentHotObject) Invalidate(); } COpenGLView::OnMouseMove(nFlags, point); }
void World::OnMouseMove(int nX, int nY) { // Although this works, the recast in ogWindowProc is a better solution. // if(nX > 32768) nX -= 65536; // if(nY > 32768) nY -= 65536; // printf("OnMouseMove: %d, %d\n", nX, nY); // fflush(stdout); UpdateMousePos(nX, nY); // lets try this - nope // RefreshPickPosition(); // Need to change this so it calls the callback during either render or update // so that the mouse pick position is up to date stringstream ss; ss << "OnMouseMove(" << m_vMouse2DPositionDelta.x << "," << m_vMouse2DPositionDelta.y << "," << nX << "," << nY << ")"; luaCall(ss.str()); if(m_bMouseMovesCamera) { if(m_bRightMouseDown) { if(glutGetModifiers() & GLUT_ACTIVE_SHIFT) { float fStepSize = m_vMouse2DPositionDelta.y * 0.2; mlVector3D vCamera = GetCameraTransform()->GetTranslation(); float fDistance = (m_vMousePickPosition - vCamera).Magnitude(); fStepSize *= fDistance * 0.05f; fStepSize = mlClamp(fStepSize, -20.0f, 20.0f); mlVector3D vForward = vCamera - m_vMousePickPosition; vForward.Normalise(); vForward *= fStepSize; m_trnCamera.ApplyTranslation(vForward); } else { PanCamera(m_vMouse2DPositionDelta.x, m_vMouse2DPositionDelta.y); } } if(m_bLeftMouseDown) { // This is a magic number which maps pixels of mouse motion to radians of rotation float fRotationSpeed = 0.008f; float fHeadingChange = fRotationSpeed * m_vMouse2DPositionDelta.x; float fPitchChange = fRotationSpeed * m_vMouse2DPositionDelta.y; if(m_bDoubleClick) { if(m_bUsePositionPreservingOrbitCamera) PositionPreservingOrbitCamera(m_vMousePickPosition, fHeadingChange * 0.5, fPitchChange * 0.5); else OrientationPreservingOrbitCamera(m_vMousePickPosition, fHeadingChange * 0.5, fPitchChange * 0.5); } else { RotateCamera(fHeadingChange, fPitchChange); } } } }
int main() { GLFWwindow* window = nullptr; glfwSetErrorCallback(error_callback); // Inititiating GLFW library if (!glfwInit()) exit(EXIT_FAILURE); // Sets hints for the next call to glfwCreateWindow - Keep these for future debugging glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); glfwWindowHint(GLFW_REFRESH_RATE, GLFW_DONT_CARE);// This hint is ignored for windowed mode windows. // Creating window window = glfwCreateWindow(640, 480, "Title", NULL, NULL); // Failure check - Creating window if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } else { fprintf(stderr, "GLFW Window initialized\n"); } // Bind key-inputs glfwSetKeyCallback(window, key_callback); // Fetch OpenGL version - Makes sure correct version is loaded from GLEW glfwMakeContextCurrent(window); // Inititiating GLEW library glewExperimental = true; GLenum err = glewInit(); // Failure check - Inititiating GLEW if (GLEW_OK != err) { fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); } else { fprintf(stderr, "GLEW initialized\n"); } #ifdef _DEBUG if (glDebugMessageCallback){ std::cout << "Register OpenGL debug callback " << std::endl; glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback((GLDEBUGPROC)openglCallbackFunction, nullptr); GLuint unusedIds = 0; glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, &unusedIds, true); } else { std::cout << "glDebugMessageCallback not available" << std::endl; } #endif // VSync glfwSwapInterval(1); //////////////////////////////////////////////////////////// // Engine classes Graphics ge = Graphics(); Physics ph = Physics(); InitMeshes(&ge); InitCameras(); ge.SetCamera(&cameras[cameraIndex]); fpsCounter fpsC; int tickCounter = 400; //////////////////////////////////////////////////////////// while (!glfwWindowShouldClose(window)) { std::stringstream ss; ss << fpsC.get(); glfwSetWindowTitle(window, ss.str().c_str()); KeyEvents(window, &ge, &ph); UpdateProjections(window); RotateCamera(&cameras[cameraIndex], window); MoveCamera(&cameras[cameraIndex], window); if (fpsC.deltaTime() > 0 && tickCounter < 1) { //ph.move(&mustangHigh, &fpsC); ph.move(&EndOfLine, &fpsC); } else { tickCounter--; } Collision(&EndOfLine, &target); Collision(&EndOfLine, &target2); ge.PrepareRender(); ge.Render(&mustang); ge.Render(&mustang2); ge.Render(&mustang3); ge.Render(&mustang4); ge.Render(&mustangHigh); ge.Render(&ground); ge.Render(&target); ge.Render(&target2); ge.Render(&EndOfLine); fpsC.tick(); Sleep(1000 / 120); glfwSwapBuffers(window); glfwPollEvents();// Processes all pending events } //////////////////////////////////////////////////////////// glfwDestroyWindow(window); glfwTerminate(); return 0; }
void BumpMapping::Update() { RotateCamera(); const f32 Angle = static_cast<f32>(io::Timer::millisecs()) / 25; dim::matrix4f Mat; Mat.rotateY(Angle); const dim::vector3df LightPos = Mat * dim::vector3df(0, 0, 3); LightObj_->setPosition(LightPos); Object2_->turn(1); if (spControl->keyHit(io::KEY_RETURN)) { if (++Mode_ > BM_STONE_NOBUMPS) Mode_ = BM_ROCKS; s32 TexIndex = 0; switch (Mode_) { case BM_ROCKS: Description_ = "BumpMapping: Rocks"; TexIndex = 0; EnableBumps_ = true; break; case BM_ROCKS_NOBUMPS: Description_ = "BumpMapping: Rocks (no bumps)"; TexIndex = 0; EnableBumps_ = false; break; case BM_STONE: Description_ = "BumpMapping: Stone"; TexIndex = 1; EnableBumps_ = true; break; case BM_STONE_NOBUMPS: Description_ = "BumpMapping: Stone (no bumps)"; TexIndex = 1; EnableBumps_ = false; break; } Object_->getMeshBuffer(0)->setTexture(0, ColorMap_[TexIndex]); Object_->getMeshBuffer(0)->setTexture(1, NormalMap_[TexIndex]); Object2_->getMeshBuffer(0)->setTexture(0, ColorMap_[TexIndex]); Object2_->getMeshBuffer(0)->setTexture(1, NormalMap_[TexIndex]); } ShdPixel_->setConstant("EnableBumps", EnableBumps_); ShdPixel_->setConstant("Light1_Position", LightPos); ShdPixel_->setConstant("Light1_Diffuse", LightColor_); ShdPixel_->setConstant("Light1_Specular", video::color(70)); ShdPixel_->setConstant("Light1_Radius", 50.0f); ShdPixel_->setConstant("Light1_Shininess", 90.0f); }