/** Called once per time frame to move the camera to the right position. * \param dt Time step. */ void Camera::update(float dt) { if (m_kart == NULL) return; // cameras not attached to kart must be positioned manually float above_kart, cam_angle, side_way, distance; bool smoothing; // The following settings give a debug camera which shows the track from // high above the kart straight down. if (UserConfigParams::m_camera_debug==1) { core::vector3df xyz = m_kart->getXYZ().toIrrVector(); m_camera->setTarget(xyz); xyz.Y = xyz.Y+55; xyz.Z -= 5.0f; m_camera->setPosition(xyz); // To view inside tunnels (FIXME 27>15 why??? makes no sense // - the kart should not be visible, but it works) m_camera->setNearValue(27.0); } else if (m_mode==CM_FINAL) { handleEndCamera(dt); } // If an explosion is happening, stop moving the camera, // but keep it target on the kart. else if (dynamic_cast<ExplosionAnimation*>(m_kart->getKartAnimation())) { getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing); // The camera target needs to be 'smooth moved', otherwise // there will be a noticable jump in the first frame // Aim at the usual same position of the kart (i.e. slightly // above the kart). core::vector3df wanted_target(m_kart->getXYZ().toIrrVector() +core::vector3df(0, above_kart, 0) ); core::vector3df current_target = m_camera->getTarget(); // Note: this code is replicated from smoothMoveCamera so that // the camera keeps on pointing to the same spot. current_target += ((wanted_target-current_target)*m_target_speed)*dt; m_camera->setTarget(current_target); } else { getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing); positionCamera(dt, above_kart, cam_angle, side_way, distance, smoothing); } if (UserConfigParams::m_graphical_effects && m_rain) { m_rain->setPosition( getCameraSceneNode()->getPosition() ); m_rain->update(dt); } // UserConfigParams::m_graphical_effects } // update
/** Called once per time frame to move the camera to the right position. * \param dt Time step. */ void CameraDebug::update(float dt) { Camera::update(dt); // To view inside tunnels in top mode, increase near value m_camera->setNearValue(m_default_debug_Type==CM_DEBUG_TOP_OF_KART ? 27.0f : 1.0f); float above_kart, cam_angle, side_way, distance; // The following settings give a debug camera which shows the track from // high above the kart straight down. if (m_default_debug_Type==CM_DEBUG_TOP_OF_KART) { core::vector3df xyz = m_kart->getXYZ().toIrrVector(); m_camera->setTarget(xyz); xyz.Y = xyz.Y+55; xyz.Z -= 5.0f; m_camera->setPosition(xyz); } else if (m_default_debug_Type==CM_DEBUG_SIDE_OF_KART) { core::vector3df xyz = m_kart->getXYZ().toIrrVector(); Vec3 offset(3, 0, 0); offset = m_kart->getTrans()(offset); m_camera->setTarget(xyz); m_camera->setPosition(offset.toIrrVector()); } // If an explosion is happening, stop moving the camera, // but keep it target on the kart. else if (dynamic_cast<ExplosionAnimation*>(m_kart->getKartAnimation())) { getCameraSettings(&above_kart, &cam_angle, &side_way, &distance); // The camera target needs to be 'smooth moved', otherwise // there will be a noticable jump in the first frame // Aim at the usual same position of the kart (i.e. slightly // above the kart). // Note: this code is replicated from smoothMoveCamera so that // the camera keeps on pointing to the same spot. core::vector3df current_target = (m_kart->getXYZ().toIrrVector() +core::vector3df(0, above_kart, 0)); m_camera->setTarget(current_target); } else { getCameraSettings(&above_kart, &cam_angle, &side_way, &distance); positionCamera(dt, above_kart, cam_angle, side_way, distance); } } // update
bool RelativePositionDetection::execute() { // TODO add angle of objects to panAngle and tiltAngle // TODO use object size in image for distance approximation mPanAngle = DEGREE_TO_RADIAN * getBodyStatus().getPan(); mTiltAngle = DEGREE_TO_RADIAN * getBodyStatus().getTilt(); const RobotConfiguration& botConf = getRobotConfiguration(); const CameraSettings& camSet = getCameraSettings(); mRadiansPerPixelH = DEGREE_TO_RADIAN * botConf.cameraOpeningHorizontal / (double) (camSet.width); mRadiansPerPixelV = DEGREE_TO_RADIAN * botConf.cameraOpeningVertical / (double) (camSet.height); mPrinciplePointX = botConf.principlePointX; mPrinciplePointY = botConf.principlePointY; mCameraHeight = botConf.cameraHeight; mCameraOffsetX = botConf.cameraOffsetX; updateVector(getBall(), &getBallVector()); updateVectors( getGoalPoles().getObjects(), &getGoalPolesVectors().data); updateVectors( getCyanRobots().getObjects(), &getCyanRobotsVectors().data); updateVectors( getMagentaRobots().getObjects(), &getMagentaRobotsVectors().data); updateVectors( getRobots().getObjects(), &getRobotsVectors().data); return true; }
void Camera::keyControl(float dtime) { int angleSpeed = getCameraSettings()->angleSpeed(); int movementSpeed = getCameraSettings()->movementSpeed(); // Update angles if (movementflags & MOVE_ROTLEFT) _angles[CAMERA_YAW] += 15 * dtime* angleSpeed; if (movementflags & MOVE_ROTRIGHT) _angles[CAMERA_YAW] -= 15 * dtime * angleSpeed; if (movementflags & MOVE_PITCHUP) { _angles[CAMERA_PITCH] += 15 * dtime* angleSpeed; if (_angles[CAMERA_PITCH] > 90) _angles[CAMERA_PITCH] = 90; } if (movementflags & MOVE_PITCHDOWN) { _angles[CAMERA_PITCH] -= 15 * dtime * angleSpeed; if (_angles[CAMERA_PITCH] < -90) _angles[CAMERA_PITCH] = -90; } updateModelview(); freemoveUpdateAxes(); // Update position if (movementflags & MOVE_FORWARD) _origin += forward * (dtime * movementSpeed); if (movementflags & MOVE_BACK) _origin += forward * (-dtime * movementSpeed); if (movementflags & MOVE_STRAFELEFT) _origin += right * (-dtime * movementSpeed); if (movementflags & MOVE_STRAFERIGHT) _origin += right * (dtime * movementSpeed); if (movementflags & MOVE_UP) _origin += g_vector3_axis_z * (dtime * movementSpeed); if (movementflags & MOVE_DOWN) _origin += g_vector3_axis_z * (-dtime * movementSpeed); updateModelview(); }
void Camera::freeMove(int dx, int dy) { int angleSpeed = getCameraSettings()->angleSpeed(); // free strafe mode, toggled by the keyboard modifiers if (m_strafe) { const float strafespeed = GlobalEventManager().MouseEvents().getCameraStrafeSpeed(); const float forwardStrafeFactor = GlobalEventManager().MouseEvents().getCameraForwardStrafeFactor(); _origin -= vright * strafespeed * dx; if (m_strafe_forward) { _origin += vpn * strafespeed * dy * forwardStrafeFactor; } else { _origin += vup * strafespeed * dy; } } else { // free rotation const float dtime = 0.1f; const float zAxisFactor = getCameraSettings()->invertMouseVerticalAxis() ? -1.0f : 1.0f; _angles[CAMERA_PITCH] += dy * dtime * angleSpeed * zAxisFactor; _angles[CAMERA_YAW] += dx * dtime * angleSpeed; if (_angles[CAMERA_PITCH] > 90) _angles[CAMERA_PITCH] = 90; else if (_angles[CAMERA_PITCH] < -90) _angles[CAMERA_PITCH] = -90; if (_angles[CAMERA_YAW] >= 360) _angles[CAMERA_YAW] -=360; else if (_angles[CAMERA_YAW] <= 0) _angles[CAMERA_YAW] +=360; } updateModelview(); freemoveUpdateAxes(); }
void CamWnd::removeHandlersMove() { g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_selection_button_press_handler); g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_selection_button_release_handler); g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_selection_motion_handler); g_signal_handler_disconnect(G_OBJECT(m_gl_widget), m_freelook_button_press_handler); // Disable either the free-look movement commands or the discrete ones, depending on the selection if (getCameraSettings()->discreteMovement()) { disableDiscreteMoveEvents(); } else { disableFreeMoveEvents(); } }
void CamWnd::addHandlersMove() { m_selection_button_press_handler = g_signal_connect(G_OBJECT(m_gl_widget), "button_press_event", G_CALLBACK(selection_button_press), m_window_observer); m_selection_button_release_handler = g_signal_connect(G_OBJECT(m_gl_widget), "button_release_event", G_CALLBACK(selection_button_release), m_window_observer); m_selection_motion_handler = g_signal_connect(G_OBJECT(m_gl_widget), "motion_notify_event", G_CALLBACK(DeferredMotion::gtk_motion), &m_deferred_motion); m_freelook_button_press_handler = g_signal_connect(G_OBJECT(m_gl_widget), "button_press_event", G_CALLBACK(enable_freelook_button_press), this); // Enable either the free-look movement commands or the discrete ones, depending on the selection if (getCameraSettings()->discreteMovement()) { enableDiscreteMoveEvents(); } else { enableFreeMoveEvents(); } }
void Camera::mouseControl(int x, int y) { int movementSpeed = getCameraSettings()->movementSpeed(); float xf, yf; xf = (float)(x - width/2) / (width/2); yf = (float)(y - height/2) / (height/2); xf *= 1.0f - fabsf(yf); if (xf < 0) { xf += 0.1f; if (xf > 0) xf = 0; } else { xf -= 0.1f; if (xf < 0) xf = 0; } _origin += forward * (yf * 0.1f* movementSpeed); _angles[CAMERA_YAW] += xf * -0.1f * movementSpeed; updateModelview(); }
void CamWnd::cubicScaleOut () { getCameraSettings()->setCubicScale( getCameraSettings()->cubicScale() + 1 ); m_Camera.updateProjection(); update(); }
void CamWnd::Cam_Draw() { glViewport(0, 0, m_Camera.width, m_Camera.height); // enable depth buffer writes glDepthMask(GL_TRUE); Vector3 clearColour(0, 0, 0); clearColour = ColourSchemes().getColourVector3("camera_background"); glClearColor(clearColour[0], clearColour[1], clearColour[2], 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); render::RenderStatistics::Instance().resetStats(); Cull_ResetStats(); glMatrixMode(GL_PROJECTION); glLoadMatrixf(m_Camera.projection); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(m_Camera.modelview); // one directional light source directly behind the viewer { GLfloat inverse_cam_dir[4], ambient[4], diffuse[4];//, material[4]; ambient[0] = ambient[1] = ambient[2] = 0.4f; ambient[3] = 1.0f; diffuse[0] = diffuse[1] = diffuse[2] = 0.4f; diffuse[3] = 1.0f; inverse_cam_dir[0] = m_Camera.vpn[0]; inverse_cam_dir[1] = m_Camera.vpn[1]; inverse_cam_dir[2] = m_Camera.vpn[2]; inverse_cam_dir[3] = 0; glLightfv(GL_LIGHT0, GL_POSITION, inverse_cam_dir); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glEnable(GL_LIGHT0); } unsigned int globalstate = RENDER_DEPTHTEST | RENDER_COLOURWRITE | RENDER_DEPTHWRITE | RENDER_ALPHATEST | RENDER_BLEND | RENDER_CULLFACE | RENDER_COLOURARRAY | RENDER_COLOURCHANGE; switch (getCameraSettings()->getMode()) { case drawWire: break; case drawSolid: globalstate |= (RENDER_FILL | RENDER_LIGHTING | RENDER_SMOOTH | RENDER_SCALED); break; case drawTexture: globalstate |= (RENDER_FILL | RENDER_LIGHTING | RENDER_TEXTURE_2D | RENDER_SMOOTH | RENDER_SCALED); break; default: globalstate = 0; break; } if (!getCameraSettings()->solidSelectionBoxes()) { globalstate |= RENDER_LINESTIPPLE; } { CamRenderer renderer(globalstate, m_state_select2, m_state_select1, m_view.getViewer()); Scene_Render(renderer, m_view); renderer.render(m_Camera.modelview, m_Camera.projection); } // greebo: Draw the clipper's points (skipping the depth-test) { glDisable(GL_DEPTH_TEST); glColor4f(1, 1, 1, 1); glPointSize(5); if (GlobalClipper().clipMode()) { GlobalClipper().draw(1.0f); } glPointSize(1); } // prepare for 2d stuff glColor4f(1, 1, 1, 1); glDisable(GL_BLEND); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, (float) m_Camera.width, 0, (float) m_Camera.height, -100, 100); glScalef(1, -1, 1); glTranslatef(0, -(float) m_Camera.height, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (GlobalOpenGL().GL_1_3()) { glClientActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0); } glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); glDisable(GL_DEPTH_TEST); glLineWidth(1); // draw the crosshair if (m_bFreeMove) { glBegin(GL_LINES); glVertex2f((float) m_Camera.width / 2.f, (float) m_Camera.height / 2.f + 6); glVertex2f((float) m_Camera.width / 2.f, (float) m_Camera.height / 2.f + 2); glVertex2f((float) m_Camera.width / 2.f, (float) m_Camera.height / 2.f - 6); glVertex2f((float) m_Camera.width / 2.f, (float) m_Camera.height / 2.f - 2); glVertex2f((float) m_Camera.width / 2.f + 6, (float) m_Camera.height / 2.f); glVertex2f((float) m_Camera.width / 2.f + 2, (float) m_Camera.height / 2.f); glVertex2f((float) m_Camera.width / 2.f - 6, (float) m_Camera.height / 2.f); glVertex2f((float) m_Camera.width / 2.f - 2, (float) m_Camera.height / 2.f); glEnd(); } glRasterPos3f(1.0f, static_cast<float> (m_Camera.height) - 1.0f, 0.0f); GlobalOpenGL().drawString(render::RenderStatistics::Instance().getStatString()); glRasterPos3f(1.0f, static_cast<float> (m_Camera.height) - 11.0f, 0.0f); GlobalOpenGL().drawString(Cull_GetStats()); // bind back to the default texture so that we don't have problems // elsewhere using/modifying texture maps between contexts glBindTexture(GL_TEXTURE_2D, 0); }
// greebo: The GTK Callback during freemove mode for scroll events. gboolean CamWnd::wheelmove_scroll(GtkWidget* widget, GdkEventScroll* event, CamWnd* camwnd) { // Set the GTK focus to this widget gtk_widget_grab_focus(widget); // Determine the direction we are moving. if (event->direction == GDK_SCROLL_UP) { camwnd->getCamera().freemoveUpdateAxes(); camwnd->setCameraOrigin(camwnd->getCameraOrigin() + camwnd->getCamera().forward * static_cast<float>(getCameraSettings()->movementSpeed())); } else if (event->direction == GDK_SCROLL_DOWN) { camwnd->getCamera().freemoveUpdateAxes(); camwnd->setCameraOrigin(camwnd->getCameraOrigin() + camwnd->getCamera().forward * (-static_cast<float>(getCameraSettings()->movementSpeed()))); } return FALSE; }
float Camera::getFarClipPlane() const { return (farClipEnabled()) ? pow(2.0, (getCameraSettings()->cubicScale() + 7) / 2.0) : 32768.0f; }
bool Camera::farClipEnabled() const { return getCameraSettings()->farClipEnabled(); }
void GlobalCameraManager::toggleLightingMode(const cmd::ArgumentList& args) { getCameraSettings()->toggleLightingMode(); }
void GlobalCameraManager::registerCommands() { GlobalCommandSystem().addCommand("CenterView", boost::bind(&GlobalCameraManager::resetCameraAngles, this, _1)); GlobalCommandSystem().addCommand("CubicClipZoomIn", boost::bind(&GlobalCameraManager::cubicScaleIn, this, _1)); GlobalCommandSystem().addCommand("CubicClipZoomOut", boost::bind(&GlobalCameraManager::cubicScaleOut, this, _1)); GlobalCommandSystem().addCommand("UpFloor", boost::bind(&GlobalCameraManager::changeFloorUp, this, _1)); GlobalCommandSystem().addCommand("DownFloor", boost::bind(&GlobalCameraManager::changeFloorDown, this, _1)); // angua: increases and decreases the movement speed of the camera GlobalCommandSystem().addCommand("CamIncreaseMoveSpeed", boost::bind(&GlobalCameraManager::increaseCameraSpeed, this, _1)); GlobalCommandSystem().addCommand("CamDecreaseMoveSpeed", boost::bind(&GlobalCameraManager::decreaseCameraSpeed, this, _1)); GlobalCommandSystem().addCommand("TogglePreview", boost::bind(&GlobalCameraManager::toggleLightingMode, this, _1)); // Insert movement commands GlobalCommandSystem().addCommand("CameraForward", boost::bind(&GlobalCameraManager::moveForwardDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraBack", boost::bind(&GlobalCameraManager::moveBackDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraLeft", boost::bind(&GlobalCameraManager::rotateLeftDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraRight", boost::bind(&GlobalCameraManager::rotateRightDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraStrafeRight", boost::bind(&GlobalCameraManager::moveRightDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraStrafeLeft", boost::bind(&GlobalCameraManager::moveLeftDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraUp", boost::bind(&GlobalCameraManager::moveUpDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraDown", boost::bind(&GlobalCameraManager::moveDownDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraAngleUp", boost::bind(&GlobalCameraManager::pitchUpDiscrete, this, _1)); GlobalCommandSystem().addCommand("CameraAngleDown", boost::bind(&GlobalCameraManager::pitchDownDiscrete, this, _1)); // Bind the events to the commands GlobalEventManager().addCommand("CenterView", "CenterView"); GlobalEventManager().addToggle("ToggleCubicClip", boost::bind(&CameraSettings::toggleFarClip, getCameraSettings(), _1)); // Set the default status of the cubic clip GlobalEventManager().setToggled("ToggleCubicClip", getCameraSettings()->farClipEnabled()); GlobalEventManager().addCommand("CubicClipZoomIn", "CubicClipZoomIn"); GlobalEventManager().addCommand("CubicClipZoomOut", "CubicClipZoomOut"); GlobalEventManager().addCommand("UpFloor", "UpFloor"); GlobalEventManager().addCommand("DownFloor", "DownFloor"); GlobalEventManager().addWidgetToggle("ToggleCamera"); GlobalEventManager().setToggled("ToggleCamera", true); // angua: increases and decreases the movement speed of the camera GlobalEventManager().addCommand("CamIncreaseMoveSpeed", "CamIncreaseMoveSpeed"); GlobalEventManager().addCommand("CamDecreaseMoveSpeed", "CamDecreaseMoveSpeed"); GlobalEventManager().addCommand("TogglePreview", "TogglePreview"); // Insert movement commands GlobalEventManager().addCommand("CameraForward", "CameraForward"); GlobalEventManager().addCommand("CameraBack", "CameraBack"); GlobalEventManager().addCommand("CameraLeft", "CameraLeft"); GlobalEventManager().addCommand("CameraRight", "CameraRight"); GlobalEventManager().addCommand("CameraStrafeRight", "CameraStrafeRight"); GlobalEventManager().addCommand("CameraStrafeLeft", "CameraStrafeLeft"); GlobalEventManager().addCommand("CameraUp", "CameraUp"); GlobalEventManager().addCommand("CameraDown", "CameraDown"); GlobalEventManager().addCommand("CameraAngleUp", "CameraAngleUp"); GlobalEventManager().addCommand("CameraAngleDown", "CameraAngleDown"); GlobalEventManager().addKeyEvent("CameraFreeMoveForward", boost::bind(&GlobalCameraManager::onFreelookMoveForwardKey, this, _1)); GlobalEventManager().addKeyEvent("CameraFreeMoveBack", boost::bind(&GlobalCameraManager::onFreelookMoveBackKey, this, _1)); GlobalEventManager().addKeyEvent("CameraFreeMoveLeft", boost::bind(&GlobalCameraManager::onFreelookMoveLeftKey, this, _1)); GlobalEventManager().addKeyEvent("CameraFreeMoveRight", boost::bind(&GlobalCameraManager::onFreelookMoveRightKey, this, _1)); GlobalEventManager().addKeyEvent("CameraFreeMoveUp", boost::bind(&GlobalCameraManager::onFreelookMoveUpKey, this, _1)); GlobalEventManager().addKeyEvent("CameraFreeMoveDown", boost::bind(&GlobalCameraManager::onFreelookMoveDownKey, this, _1)); }