void TinyGLRenderer::setupCameraPerspective(float pitch, float heading, float fov) { // TODO: Find a correct and exact formula for the FOV TGLfloat glFOV = 0.63 * fov; // Approximative and experimental formula if (fov > 79.0 && fov < 81.0) glFOV = 50.5; // Somewhat good value for fov == 80 else if (fov > 59.0 && fov < 61.0) glFOV = 36.0; // Somewhat good value for fov == 60 // NOTE: tinyGL viewport implementation needs to be checked as it doesn't behave the same as openGL tglViewport(0, kTopBorderHeight, kOriginalWidth, kFrameHeight); tglMatrixMode(TGL_PROJECTION); tglLoadIdentity(); Math::Matrix4 m = Math::makePerspectiveMatrix(glFOV, (TGLfloat)kOriginalWidth / (TGLfloat)kFrameHeight, 1.0, 10000.0); tglMultMatrixf(m.getData()); // Rotate the model to simulate the rotation of the camera tglMatrixMode(TGL_MODELVIEW); tglLoadIdentity(); tglRotatef(pitch, -1.0f, 0.0f, 0.0f); tglRotatef(heading - 180.0f, 0.0f, 1.0f, 0.0f); tglGetFloatv(TGL_MODELVIEW_MATRIX, _cubeModelViewMatrix); tglGetFloatv(TGL_PROJECTION_MATRIX, _cubeProjectionMatrix); tglGetIntegerv(TGL_VIEWPORT, (TGLint *)_cubeViewport); }
// Spinning Cube! inline void scene2(float scene_time) { int i = scene_time / 25; tglClear(TGL_COLOR_BUFFER_BIT); float zoom = 0; if(scene_time > 5000) zoom = 0.5*sin((float)(i-20)/10.0); float rot_speed = 1.0; if(scene_time > 12000) rot_speed += (float)(scene_time - 12000) / 1500.0; tglMatrixMode(TGL_MODELVIEW); tglLoadIdentity(); tglTranslatef(0, 0, -2.5+zoom); tglRotatef((float)(i % 360) * rot_speed, 0, 1, 0); tglRotatef((float)(i % 360) * rot_speed, 1, 1, 0); tglBegin(TGL_LINES); for(int p=0; p<8; ++p) { tglVertex3fv(cube[cubestrip1[p]]); } tglEnd(); tglBegin(TGL_LINES); for(int p=0; p<8; ++p) { tglVertex3fv(cube[cubestrip2[p]]); } tglEnd(); tglSwap(); }
void GfxTinyGL::startActorDraw(Graphics::Vector3d pos, float scale, float yaw, float pitch, float roll) { tglEnable(TGL_TEXTURE_2D); tglMatrixMode(TGL_MODELVIEW); tglPushMatrix(); if (_currentShadowArray) { // TODO find out why shadowMask at device in woods is null if (!_currentShadowArray->shadowMask) { _currentShadowArray->shadowMask = new byte[_screenWidth * _screenHeight]; _currentShadowArray->shadowMaskSize = _screenWidth * _screenHeight; } assert(_currentShadowArray->shadowMask); //tglSetShadowColor(255, 255, 255); tglSetShadowColor(_shadowColorR, _shadowColorG, _shadowColorB); tglSetShadowMaskBuf(_currentShadowArray->shadowMask); SectorListType::iterator i = _currentShadowArray->planeList.begin(); Sector *shadowSector = i->sector; tglShadowProjection(_currentShadowArray->pos, shadowSector->getVertices()[0], shadowSector->getNormal(), _currentShadowArray->dontNegate); } tglTranslatef(pos.x(), pos.y(), pos.z()); tglScalef(scale, scale, scale); tglRotatef(yaw, 0, 0, 1); tglRotatef(pitch, 1, 0, 0); tglRotatef(roll, 0, 1, 0); }
void GfxTinyGL::translateViewpointStart(Graphics::Vector3d pos, float pitch, float yaw, float roll) { tglPushMatrix(); tglTranslatef(pos.x(), pos.y(), pos.z()); tglRotatef(yaw, 0, 0, 1); tglRotatef(pitch, 1, 0, 0); tglRotatef(roll, 0, 1, 0); }
void GfxTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) { tglMatrixMode(TGL_PROJECTION); tglLoadIdentity(); float right = nclip * tan(fov / 2 * (LOCAL_PI / 180)); tglFrustum(-right, right, -right * 0.75, right * 0.75, nclip, fclip); tglMatrixMode(TGL_MODELVIEW); tglLoadIdentity(); tglRotatef(roll, 0, 0, -1); }