void MenuRenderer::render(UIComponent *component) { if(component->isHidden) return; UIAnimator *animator = component->getActiveAnimator(); UIManager *uiManager = context->uiManager; if (animator) { animator->drawPreComponent(context); } // if virtual size bigger than drawable area, scissor to drawable if (component->isVirtualLargerThanDrawable()) { glEnable(GL_SCISSOR_TEST); glScissor(component->left, context->gConfig->viewportHeight - component->bottom, component->right - component->left, component->bottom - component->top); } if (!component->isEnabled) { context->renderContext->colorFilter = Vector4f(0.5f,0.5f,0.5f,1.0f); } else { context->renderContext->colorFilter = Vector4f(1,1,1,1); } // draw this component first then recurse children S32 menuResourceId = component->backgroundMenuResourceId; if (component->isPressed) { if (component->pressedBackgroundMenuResourceId != NO_RESOURCE) { menuResourceId = component->pressedBackgroundMenuResourceId; } } else { if (uiManager->selectedComponent == component) { if (component->selectedBackgroundMenuResourceId != NO_RESOURCE) { menuResourceId = component->selectedBackgroundMenuResourceId; } } } if (menuResourceId != NO_RESOURCE) { Texture *texture = context->glResourceManager->getTexture(getAssetNameForResource(menuResourceId)); if (menuResourceId != activeResourceId) { if (texture) { texture->bind(); } activeResourceId = menuResourceId; } context->quadRenderer->render(texture, component->virtualTop, component->virtualRight, component->virtualBottom, component->virtualLeft); } if (component->text) { if (component->isEnabled) { context->renderContext->colorFilter = Vector4f(component->textR,component->textB,component->textG,component->textA); } else { context->renderContext->colorFilter = Vector4f(component->textR*0.5f,component->textB*0.5f,component->textG*0.5f,component->textA); } // starting a text render means we're switching textures activeResourceId = -1; // TODO - optimize for 1 pass text F32 componentWidth = component->virtualRight - component->virtualLeft; F32 componentHeight = component->virtualBottom - component->virtualTop; F32 textWidth = textRenderer->measureWidth(component->text); F32 textLineHeight = textRenderer->getHeight(); F32 totalTextHeight = textLineHeight; if (component->isTextMultiline) { // take padding into account totalTextHeight = textRenderer->measureMultilineHeight(component->text, componentWidth - (component->paddingLeftDips + component->paddingRightDips) * context->gConfig->uiScale); } F32 textBottomOffset = totalTextHeight - textLineHeight; F32 textLeft = component->virtualLeft; // confusing - textBottom refers to the bottom of the _first_ row of text, which is the top row in multiline. F32 textBottom = component->virtualBottom; if (component->textHorizontalAlignment == UIComponent::LEFT) { textLeft += component->paddingLeftDips * context->gConfig->uiScale; } else if (component->textHorizontalAlignment == UIComponent::HORIZONTAL_CENTER) { textLeft += (componentWidth / 2 - textWidth / 2); } else if (component->textHorizontalAlignment == UIComponent::RIGHT) { textLeft += (componentWidth - textWidth) - component->paddingRightDips * context->gConfig->uiScale; } if (component->textVerticalAlignment == UIComponent::BOTTOM) { textBottom -= textBottomOffset; textBottom -= component->paddingBottomDips * context->gConfig->uiScale; } else if (component->textVerticalAlignment == UIComponent::VERTICAL_CENTER) { textBottom -= (componentHeight / 2 + totalTextHeight / 2) - textLineHeight; } else if (component->textVerticalAlignment == UIComponent::TOP) { textBottom -= (componentHeight - textLineHeight) - component->paddingTopDips * context->gConfig->uiScale; } if (textLeft < component->virtualLeft + component->paddingLeftDips * context->gConfig->uiScale) { textLeft = component->virtualLeft + component->paddingLeftDips * context->gConfig->uiScale; } if (textBottom > component->virtualBottom - component->paddingBottomDips * context->gConfig->uiScale) { textBottom = component->virtualBottom - component->paddingBottomDips * context->gConfig->uiScale; } textRenderer->startText(); if (component->isTextMultiline) { textRenderer->renderMultiline(component->text, textLeft, textBottom, component->virtualRight - component->paddingRightDips * context->gConfig->uiScale, component->virtualBottom - component->paddingBottomDips * context->gConfig->uiScale); } else { textRenderer->render(component->text, textLeft, textBottom); } textRenderer->finishText(); } if (component->components->getSize() > 0) { // recurse through layout's components UIComponent **components = component->components->array; int i; for (i = 0; i < component->components->getSize(); i++) { render(components[i]); } } context->renderContext->colorFilter = Vector4f(1,1,1,1); if (component->isVirtualLargerThanDrawable()) { glDisable(GL_SCISSOR_TEST); } if (animator) { animator->drawPostComponent(context); } }
void InfiniTAMApp::RenderGL(void) { glClear(GL_COLOR_BUFFER_BIT); if (!IsInitialized()) return; if (mNewWindowSize.x > 0) { Vector2i depthImageSize = mMainEngine->GetImageSize(); float ratio = (float)depthImageSize.x/(float)depthImageSize.y; // glViewport(0, 0, newWidth, newHeight); if (mNewWindowSize.x >= mNewWindowSize.y) { winPos[0] = Vector4f(0.0f, 0.0f, 1.0f/ratio, 1.0f); winPos[1] = Vector4f(1.0f/ratio, 0.5f, 1.0f, 1.0f); winPos[2] = Vector4f(1.0f/ratio, 0.0f, 1.0f, 0.5f); } else { winPos[0] = Vector4f(0.0f, 1.0f/3.0f, 1.0f, 1.0f); winPos[1] = Vector4f(0.0f, 0.0f, 0.5f, 1.0f/3.0f); winPos[2] = Vector4f(0.5f, 0.0f, 1.0f, 1.0f/3.0f); } mNewWindowSize.x = mNewWindowSize.y = -1; } int localNumWin = 1;//NUM_WIN for (int w = 0; w < localNumWin; w++) mMainEngine->GetImage(outImage[w], winImageType[w]); glMatrixMode(GL_PROJECTION); glPushMatrix(); { glLoadIdentity(); glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); { glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); for (int w = 0; w < localNumWin; w++) { glBindTexture(GL_TEXTURE_2D, textureId[w]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, outImage[w]->noDims.x, outImage[w]->noDims.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, outImage[w]->GetData(MEMORYDEVICE_CPU)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); float vertices[] = { winPos[w][0], winPos[w][3], winPos[w][2], winPos[w][3], winPos[w][0], winPos[w][1], winPos[w][2], winPos[w][1] }; float texture[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; glVertexPointer(2, GL_FLOAT, 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, texture); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); } glPopMatrix(); } glMatrixMode(GL_PROJECTION); glPopMatrix(); }
bool DeferredPhongLightingPass::Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned secondWorkTexture) const { NazaraAssert(sceneData.viewer, "Invalid viewer"); NazaraUnused(secondWorkTexture); m_workRTT->SetColorTarget(firstWorkTexture); Renderer::SetTarget(m_workRTT); Renderer::SetViewport(Recti(0, 0, m_dimensions.x, m_dimensions.y)); Renderer::SetTexture(0, m_GBuffer[0]); Renderer::SetTextureSampler(0, m_pointSampler); Renderer::SetTexture(1, m_GBuffer[1]); Renderer::SetTextureSampler(1, m_pointSampler); Renderer::SetTexture(2, m_GBuffer[2]); Renderer::SetTextureSampler(2, m_pointSampler); Renderer::SetTexture(3, m_depthStencilTexture); Renderer::SetTextureSampler(3, m_pointSampler); Renderer::SetClearColor(Color::Black); Renderer::Clear(RendererBuffer_Color); RenderStates lightStates; lightStates.dstBlend = BlendFunc_One; lightStates.srcBlend = BlendFunc_One; lightStates.blending = true; lightStates.depthBuffer = false; lightStates.depthWrite = false; // Directional lights if (!m_renderQueue->directionalLights.empty()) { Renderer::SetRenderStates(lightStates); Renderer::SetShader(m_directionalLightShader); m_directionalLightShader->SendColor(m_directionalLightShaderSceneAmbientLocation, sceneData.ambientColor); m_directionalLightShader->SendVector(m_directionalLightShaderEyePositionLocation, sceneData.viewer->GetEyePosition()); for (auto& light : m_renderQueue->directionalLights) { m_directionalLightShader->SendColor(m_directionalLightUniforms.locations.color, light.color); m_directionalLightShader->SendVector(m_directionalLightUniforms.locations.factors, Vector2f(light.ambientFactor, light.diffuseFactor)); m_directionalLightShader->SendVector(m_directionalLightUniforms.locations.parameters1, Vector4f(light.direction)); Renderer::DrawFullscreenQuad(); } } // Point lights/Spot lights if (!m_renderQueue->pointLights.empty() || !m_renderQueue->spotLights.empty()) { // http://www.altdevblogaday.com/2011/08/08/stencil-buffer-optimisation-for-deferred-lights/ lightStates.cullingSide = FaceSide_Front; lightStates.stencilTest = true; lightStates.stencilDepthFail.back = StencilOperation_Invert; lightStates.stencilDepthFail.front = StencilOperation_Invert; lightStates.stencilFail.back = StencilOperation_Keep; lightStates.stencilFail.front = StencilOperation_Keep; lightStates.stencilPass.back = StencilOperation_Keep; lightStates.stencilPass.front = StencilOperation_Keep; lightStates.stencilReference.back = 0; lightStates.stencilReference.front = 0; lightStates.stencilWriteMask.back = 0xFF; lightStates.stencilWriteMask.front = 0xFF; Renderer::SetRenderStates(lightStates); Renderer::SetShader(m_pointSpotLightShader); m_pointSpotLightShader->SendColor(m_pointSpotLightShaderSceneAmbientLocation, sceneData.ambientColor); m_pointSpotLightShader->SendVector(m_pointSpotLightShaderEyePositionLocation, sceneData.viewer->GetEyePosition()); Matrix4f lightMatrix; lightMatrix.MakeIdentity(); if (!m_renderQueue->pointLights.empty()) { const IndexBuffer* indexBuffer = m_sphereMesh->GetIndexBuffer(); Renderer::SetIndexBuffer(indexBuffer); Renderer::SetVertexBuffer(m_sphereMesh->GetVertexBuffer()); m_pointSpotLightShader->SendInteger(m_pointSpotLightUniforms.locations.type, LightType_Point); for (const auto& light : m_renderQueue->pointLights) { m_pointSpotLightShader->SendColor(m_pointSpotLightUniforms.locations.color, light.color); m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.factors, Vector2f(light.ambientFactor, light.diffuseFactor)); m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters1, Vector4f(light.position, light.attenuation)); m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters2, Vector4f(0.f, 0.f, 0.f, light.invRadius)); lightMatrix.SetScale(Vector3f(light.radius * 1.1f)); // To correct imperfections due to the sphere lightMatrix.SetTranslation(light.position); Renderer::SetMatrix(MatrixType_World, lightMatrix); // Sphere rendering in the stencil buffer Renderer::Enable(RendererParameter_ColorWrite, false); Renderer::Enable(RendererParameter_DepthBuffer, true); Renderer::Enable(RendererParameter_FaceCulling, false); Renderer::SetStencilCompareFunction(RendererComparison_Always); m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, true); Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); // Sphere rendering as effect zone Renderer::Enable(RendererParameter_ColorWrite, true); Renderer::Enable(RendererParameter_DepthBuffer, false); Renderer::Enable(RendererParameter_FaceCulling, true); Renderer::SetStencilCompareFunction(RendererComparison_NotEqual, FaceSide_Back); Renderer::SetStencilPassOperation(StencilOperation_Zero, FaceSide_Back); m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, false); Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); } if (m_lightMeshesDrawing) { Renderer::Enable(RendererParameter_DepthBuffer, true); Renderer::Enable(RendererParameter_DepthWrite, true); Renderer::Enable(RendererParameter_FaceCulling, false); Renderer::Enable(RendererParameter_StencilTest, false); Renderer::SetFaceFilling(FaceFilling_Line); const Shader* shader = ShaderLibrary::Get("DebugSimple"); static int colorLocation = shader->GetUniformLocation("Color"); Renderer::SetShader(shader); for (const auto& light : m_renderQueue->pointLights) { lightMatrix.SetScale(Vector3f(light.radius * 1.1f)); // To correct imperfections due to the sphere lightMatrix.SetTranslation(light.position); Renderer::SetMatrix(MatrixType_World, lightMatrix); shader->SendColor(colorLocation, light.color); Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); } Renderer::Enable(RendererParameter_DepthBuffer, false); Renderer::Enable(RendererParameter_DepthWrite, false); Renderer::Enable(RendererParameter_FaceCulling, true); Renderer::Enable(RendererParameter_StencilTest, true); Renderer::SetFaceFilling(FaceFilling_Fill); } } if (!m_renderQueue->spotLights.empty()) { const IndexBuffer* indexBuffer = m_coneMesh->GetIndexBuffer(); Renderer::SetIndexBuffer(indexBuffer); Renderer::SetVertexBuffer(m_coneMesh->GetVertexBuffer()); m_pointSpotLightShader->SendInteger(m_pointSpotLightUniforms.locations.type, LightType_Spot); for (const auto& light : m_renderQueue->spotLights) { m_pointSpotLightShader->SendColor(m_pointSpotLightUniforms.locations.color, light.color); m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.factors, Vector2f(light.ambientFactor, light.diffuseFactor)); m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters1, Vector4f(light.position, light.attenuation)); m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters2, Vector4f(light.direction, light.invRadius)); m_pointSpotLightShader->SendVector(m_pointSpotLightUniforms.locations.parameters3, Vector2f(light.innerAngleCosine, light.outerAngleCosine)); float baseRadius = light.radius * light.outerAngleTangent * 1.1f; lightMatrix.MakeTransform(light.position, Quaternionf::RotationBetween(Vector3f::Forward(), light.direction), Vector3f(baseRadius, baseRadius, light.radius)); Renderer::SetMatrix(MatrixType_World, lightMatrix); // Sphere rendering in the stencil buffer Renderer::Enable(RendererParameter_ColorWrite, false); Renderer::Enable(RendererParameter_DepthBuffer, true); Renderer::Enable(RendererParameter_FaceCulling, false); Renderer::SetStencilCompareFunction(RendererComparison_Always); m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, true); Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); // Sphere rendering as effect zone Renderer::Enable(RendererParameter_ColorWrite, true); Renderer::Enable(RendererParameter_DepthBuffer, false); Renderer::Enable(RendererParameter_FaceCulling, true); Renderer::SetFaceCulling(FaceSide_Front); Renderer::SetStencilCompareFunction(RendererComparison_NotEqual, FaceSide_Back); Renderer::SetStencilPassOperation(StencilOperation_Zero, FaceSide_Back); m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, false); Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); } if (m_lightMeshesDrawing) { Renderer::Enable(RendererParameter_DepthBuffer, true); Renderer::Enable(RendererParameter_DepthWrite, true); Renderer::Enable(RendererParameter_FaceCulling, false); Renderer::Enable(RendererParameter_StencilTest, false); Renderer::SetFaceFilling(FaceFilling_Line); const Shader* shader = ShaderLibrary::Get("DebugSimple"); static int colorLocation = shader->GetUniformLocation("Color"); Renderer::SetShader(shader); for (const auto& light : m_renderQueue->spotLights) { float baseRadius = light.radius * light.outerAngleTangent * 1.1f; lightMatrix.MakeTransform(light.position, Quaternionf::RotationBetween(Vector3f::Forward(), light.direction), Vector3f(baseRadius, baseRadius, light.radius)); Renderer::SetMatrix(MatrixType_World, lightMatrix); shader->SendColor(colorLocation, light.color); Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount()); } Renderer::Enable(RendererParameter_DepthBuffer, false); Renderer::Enable(RendererParameter_DepthWrite, false); Renderer::Enable(RendererParameter_FaceCulling, true); Renderer::Enable(RendererParameter_StencilTest, true); Renderer::SetFaceFilling(FaceFilling_Fill); } } Renderer::Enable(RendererParameter_StencilTest, false); } return true; }
void Mission::ThirdPersonCamera::onUpdateActivity(float dt) { assert( _scene ); _positionModeTimeout -= dt; _positionModeTimeout = _positionModeTimeout < 0 ? 0 : _positionModeTimeout; // retrieve action channels ActionChannel* headLeft = Gameplay::iGameplay->getActionChannel( iaHeadLeft ); ActionChannel* headRight = Gameplay::iGameplay->getActionChannel( iaHeadRight ); ActionChannel* headUp = Gameplay::iGameplay->getActionChannel( iaHeadUp ); ActionChannel* headDown = Gameplay::iGameplay->getActionChannel( iaHeadDown ); ActionChannel* zoomIn = Gameplay::iGameplay->getActionChannel( iaZoomIn ); ActionChannel* zoomOut = Gameplay::iGameplay->getActionChannel( iaZoomOut ); if( _positionMode ) { // field of view _cameraFOV = ( 60.0f - 55.0f * ( zoomIn->getAmplitude() ) ) * CAMERA_FOV_MULTIPLIER; // target position Matrix4f targetPose( 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 ); if( _target ) targetPose = _target->getPose(); Vector3f targetPos( targetPose[3][0], targetPose[3][1], targetPose[3][2] ); if( dynamic_cast<Jumper*>( _target ) ) { Jumper* j = dynamic_cast<Jumper*>( _target ); j->getClump()->getFrame()->getLTM(); engine::IFrame* backBone = Jumper::getBackBone( j->getClump() ); targetPos = backBone->getPos(); } // camera direction Vector3f cameraAt = _cameraPos - targetPos; cameraAt.normalize(); // camera right Vector3f cameraRight; cameraRight.cross( Vector3f(0,1,0), cameraAt ); cameraRight.normalize(); // camera up Vector3f cameraUp; cameraUp.cross( cameraAt, cameraRight ); cameraUp.normalize(); // camera matrix _cameraMatrix.set( cameraRight[0], cameraRight[1], cameraRight[2], 0.0f, cameraUp[0], cameraUp[1], cameraUp[2], 0.0f, cameraAt[0], cameraAt[1], cameraAt[2], 0.0f, _cameraPos[0], _cameraPos[1], _cameraPos[2], 1.0f ); } else { // camera offset _cameraDistance -= dt * 500.0f * zoomIn->getAmplitude(); _cameraDistance += dt * 500.0f * zoomOut->getAmplitude(); if( _cameraDistance < TPSM_MINIMAL_DISTANCE ) _cameraDistance = TPSM_MINIMAL_DISTANCE; // rotate camera _cameraTurn += 180 * dt * headLeft->getAmplitude(); _cameraTurn -= 180 * dt * headRight->getAmplitude(); _cameraTilt += 180 * dt * headUp->getAmplitude(); _cameraTilt -= 180 * dt * headDown->getAmplitude(); if( _cameraTilt < -89 ) _cameraTilt = -89; if( _cameraTilt > 89 ) _cameraTilt = 89; Matrix4f targetPose( 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 ); if( _target ) targetPose = _target->getPose(); Vector3f targetPos( targetPose[3][0], targetPose[3][1], targetPose[3][2] ); Vector3f targetOffset( 0,150,0 ); if( dynamic_cast<Jumper*>( _target ) ) { Jumper* j = dynamic_cast<Jumper*>( _target ); j->getClump()->getFrame()->getLTM(); engine::IFrame* backBone = Jumper::getBackBone( j->getClump() ); targetPos = backBone->getPos(); targetOffset.set( 0,75, 0 ); } // calculate camera matrix _cameraMatrix.set( 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 ); _cameraMatrix = Gameplay::iEngine->rotateMatrix( _cameraMatrix, Vector3f( 1,0,0 ), _cameraTilt ); _cameraMatrix = Gameplay::iEngine->rotateMatrix( _cameraMatrix, Vector3f( 0,1,0 ), _cameraTurn ); Vector3f at( _cameraMatrix[2][0], _cameraMatrix[2][1], _cameraMatrix[2][2] ); // possible camera position Vector3f cameraPos = targetPos + targetOffset + at * _cameraDistance; // clip camera distance float clipDistance = _cameraDistance; if( _scene->clipCameraRay( targetPos, cameraPos, clipDistance ) ) { _cameraDistance = clipDistance; cameraPos = targetPos + targetOffset + at * _cameraDistance; } // finalize camera matrix (translation component) _cameraMatrix = Gameplay::iEngine->translateMatrix( _cameraMatrix, cameraPos ); } // camera is actual now Gameplay::iEngine->getDefaultCamera()->setFOV( _cameraFOV ); Gameplay::iEngine->getDefaultCamera()->getFrame()->setMatrix( _cameraMatrix ); _scene->getScenery()->happen( this, EVENT_CAMERA_IS_ACTUAL ); if( _scene->getTopMode() ) _scene->getTopMode()->happen( this, EVENT_CAMERA_IS_ACTUAL ); // RT-RS pass bool flares = ( _scene->getLocation()->getWeather() == ::wtSunny ) || ( _scene->getLocation()->getWeather() == ::wtVariable ); Gameplay::iGameplay->getRenderTarget()->render( _scene, _cameraMatrix, _cameraFOV, flares, false ); // GUI Gameplay::iEngine->getDefaultCamera()->beginScene( 0, Vector4f( 0,0,0,0 ) ); if( _scene->isHUDEnabled() ) Gameplay::iGui->render(); Gameplay::iEngine->getDefaultCamera()->endScene(); // present result Gameplay::iEngine->present(); }
void Mission::onResume(void) { Gameplay::iGui->setCursorVisible( false ); Gameplay::iGui->getDesktop()->setColor( Vector4f( 0,0,0,0 ) ); if( _tpcamera ) _scene->setCamera( _tpcamera ); }
PlayGame::PlayGame() { TextureAtlasDataBase::LoadAtlases("@Atlases/atlas.json"); m_pWorld = new World(1/60.0f,15); m_pWorld->EnableDebugDraw(); m_pPGInputController = PGInputController::Initialize(); m_pPGInputController->SetMaxAcceleration(500.0f); m_backgroundTexture = new Texture2D; m_backgroundTexture->Load("@Backgrounds/spacebk1.png"); m_backgroundTexture->SetWrapMode(GL_REPEAT,GL_REPEAT); m_background = new TiledBackground; m_background->SetTexture(m_backgroundTexture); m_background->SetShading(SpriteVertex::NONE); m_background->SetDepth(2.0f); m_background->SetUVScale(0.5f,0.5f); m_background->EnableCamera(); m_particleTex = new Texture2D; m_particleTex->Load("[0]/GUI_Button.tga"); m_pEmitter = new ParticleEmitterCircle; m_pEmitter->SetAngularVelocity(15.0f,17.0f); m_pEmitter->SetParticleLife(8.0f,10.0f); m_pEmitter->SetVelocity(10.0f,15.0f); m_pEmitter->SetTexture(m_particleTex); m_pEmitter->SetPosition(Vector2f(200.0f,200.0f)); m_pEmitter->SetSpawnDelay(1.0f/10.0f); m_pEmitter->m_modifiers.push_back(new ParticleEffectorGravity()); m_pEmitter->m_modifiers.push_back(new ParticleEffectorColor(Vector4f(1.0f,1.0f,0.0f,1.0f),Vector4f(0.0f,0.0f,1.0f,0.0f))); //Texture loading m_enemyTexture=new Texture2D; m_playerTexture=new Texture2D; m_enemyTexture->Load("@Sprites/Ships/enemy1.png"); m_playerTexture->Load("@Sprites/Ships/Player.png"); //Player sprite setup m_playerSprite=new Sprite; m_playerSprite->SetTexture(m_playerTexture); m_playerSprite->SetSize(50.0f,50.0f); m_playerSprite->SetShading(SpriteVertex::ALPHA_BLEND); //Player setup m_playerObject=new Player(m_pWorld); m_playerObject->SetSprite(m_playerSprite); m_playerObject->SetPosition(Vector2f(Render::GetScreenWidth()*0.5,Render::GetScreenHeight()*0.5)); //Enemy sprite setup m_enemySprite=new Sprite; m_enemySprite->SetTexture(m_enemyTexture); m_enemySprite->SetSize(100.0f,17.0f*4.0f); m_enemySprite->SetShading(SpriteVertex::COLOR_SUM_ALPHA_BLEND); m_enemySprite->SetColor(Vector4f(0.33f,0.33f,0.33f,1.0f)); for(int i=0;i<=7;++i) { //Enemy setup m_enemyObject[0]=new Enemy(m_pWorld); m_enemyObject[0]->SetSprite(m_enemySprite); m_enemyObject[0]->SetPosition(Vector2f(50.0f,450.0f)); //Enemy setup m_enemyObject[1]=new Enemy(m_pWorld); m_enemyObject[1]->SetSprite(m_enemySprite); m_enemyObject[1]->SetPosition(Vector2f(450.0f,50.0f)); //Enemy setup m_enemyObject[2]=new Enemy(m_pWorld); m_enemyObject[2]->SetSprite(m_enemySprite); m_enemyObject[2]->SetPosition(Vector2f(450.0f,450.0f)); //Enemy setup m_enemyObject[3]=new Enemy(m_pWorld); m_enemyObject[3]->SetSprite(m_enemySprite); m_enemyObject[3]->SetPosition(Vector2f(50.0f,50.0f)); } //Camera setup Global::pActiveCamera=new Camera2D(); Global::pActiveCamera->Link(m_playerObject); //should be deleted in final version m_testTexture=new Texture2D(); m_testTexture->Load("[0]/Animations/explosion.png"); m_testSprite=new AnimatedSprite(); m_testSprite->m_position=Vector2f(Render::GetScreenWidth()*0.5,Render::GetScreenHeight()*0.5); m_testSprite->SetTexture(m_testTexture); m_testSprite->SetSize(200.0f,200.0f); m_testSprite->SetShading(SpriteVertex::ALPHA_BLEND); m_testSprite->SetLayer(1.0f); m_testSprite->BuildFrameGrid(5,4); m_testSprite->SetAnimation(Animation(0,20,10.0f)); const float FRONT_LAYER=99910000.0f; m_UIMatch1Sprite = new Sprite(); m_UIMatch1Sprite->SetTexture(m_playerTexture); m_UIMatch1Sprite->SetSize(300.0f,300.0f); m_UIMatch1Sprite->UIMatch(Anchor(Anchor::Get(Anchor::TopLeft)),Anchor(Anchor::Get(Anchor::TopLeft))); m_UIMatch1Sprite->SetLayer(FRONT_LAYER); m_UIMatch1Sprite->SetShading(SpriteVertex::ALPHA_BLEND); m_UIMatch2Sprite = new Sprite(); m_UIMatch2Sprite->SetTexture(m_playerTexture); m_UIMatch2Sprite->SetSize(300.0f,300.0f); m_UIMatch2Sprite->UIMatch(Anchor(Anchor::Get(Anchor::BottomLeft)),Anchor(Anchor::Get(Anchor::BottomLeft))); m_UIMatch2Sprite->SetLayer(FRONT_LAYER); m_UIMatch2Sprite->SetShading(SpriteVertex::ALPHA_BLEND); m_UIMatch3Sprite = new Sprite(); m_UIMatch3Sprite->SetTexture(m_playerTexture); m_UIMatch3Sprite->SetSize(300.0f,300.0f); m_UIMatch3Sprite->UIMatch(Anchor(Anchor::Get(Anchor::TopRight)),Anchor(Anchor::Get(Anchor::TopRight))); m_UIMatch3Sprite->SetLayer(FRONT_LAYER); m_UIMatch3Sprite->SetShading(SpriteVertex::ALPHA_BLEND); m_UIMatch4Sprite = new Sprite(); m_UIMatch4Sprite->SetTexture(m_playerTexture); m_UIMatch4Sprite->SetSize(300.0f,300.0f); m_UIMatch4Sprite->UIMatch(Anchor(Anchor::Get(Anchor::BottomRight)),Anchor(Anchor::Get(Anchor::BottomRight))); m_UIMatch4Sprite->SetLayer(FRONT_LAYER); m_UIMatch4Sprite->SetShading(SpriteVertex::ALPHA_BLEND); m_pWorld->LinkCollisionCallback(CollisionCallbackStruct(Physics_collisionCallback, this)); }
OvrVideoMenu::OvrVideoMenu( App * app, Oculus360Videos * videos, OvrVRMenuMgr & menuMgr, BitmapFont const & font, OvrMetaData & metaData, float fadeOutTime, float radius ) : VRMenu( MENU_NAME ) , AppPtr( app ) , MenuMgr( menuMgr ) , Font( font ) , Videos( videos ) , MetaData( metaData ) , LoadingIconHandle( 0 ) , AttributionHandle( 0 ) , BrowserButtonHandle( 0 ) , VideoControlButtonHandle( 0 ) , Radius( radius ) , ButtonCoolDown( 0.0f ) , OpenTime( 0.0 ) { // Init with empty root Init( menuMgr, font, 0.0f, VRMenuFlags_t() ); // Create Attribution info view Array< VRMenuObjectParms const * > parms; Array< VRMenuComponent* > comps; VRMenuId_t attributionPanelId( ID_CENTER_ROOT.Get() + 10 ); comps.PushBack( new OvrVideoMenuRootComponent( *this ) ); Quatf rot( DOWN, 0.0f ); Vector3f dir( -FWD ); Posef panelPose( rot, dir * Radius ); Vector3f panelScale( 1.0f ); const VRMenuFontParms fontParms( true, true, false, false, true, 0.525f, 0.45f, 1.0f ); VRMenuObjectParms attrParms( VRMENU_STATIC, comps, VRMenuSurfaceParms(), "Attribution Panel", panelPose, panelScale, Posef(), Vector3f( 1.0f ), fontParms, attributionPanelId, VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &attrParms ); AddItems( MenuMgr, Font, parms, GetRootHandle(), false ); parms.Clear(); comps.Clear(); AttributionHandle = HandleForId( MenuMgr, attributionPanelId ); VRMenuObject * attributionObject = MenuMgr.ToObject( AttributionHandle ); OVR_ASSERT( attributionObject != NULL ); //Browser button float const ICON_HEIGHT = 80.0f * VRMenuObject::DEFAULT_TEXEL_SCALE; Array< VRMenuSurfaceParms > surfParms; Posef browserButtonPose( Quatf(), UP * ICON_HEIGHT * 2.0f ); comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) ); comps.PushBack( new OvrButton_OnUp( this, ID_BROWSER_BUTTON ) ); comps.PushBack( new OvrSurfaceToggleComponent( ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "assets/nav_home_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "assets/nav_home_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); VRMenuObjectParms browserButtonParms( VRMENU_BUTTON, comps, surfParms, "", browserButtonPose, Vector3f( 1.0f ), Posef(), Vector3f( 1.0f ), fontParms, ID_BROWSER_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &browserButtonParms ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); surfParms.Clear(); BrowserButtonHandle = attributionObject->ChildHandleForId( MenuMgr, ID_BROWSER_BUTTON ); VRMenuObject * browserButtonObject = MenuMgr.ToObject( BrowserButtonHandle ); OVR_ASSERT( browserButtonObject != NULL ); OVR_UNUSED( browserButtonObject ); //Video control button Posef videoButtonPose( Quatf(), DOWN * ICON_HEIGHT * 2.0f ); comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) ); comps.PushBack( new OvrButton_OnUp( this, ID_VIDEO_BUTTON ) ); comps.PushBack( new OvrSurfaceToggleComponent( ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "assets/nav_restart_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "assets/nav_restart_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); VRMenuObjectParms controlButtonParms( VRMENU_BUTTON, comps, surfParms, "", videoButtonPose, Vector3f( 1.0f ), Posef(), Vector3f( 1.0f ), fontParms, ID_VIDEO_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &controlButtonParms ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); VideoControlButtonHandle = attributionObject->ChildHandleForId( MenuMgr, ID_VIDEO_BUTTON ); VRMenuObject * controlButtonObject = MenuMgr.ToObject( VideoControlButtonHandle ); OVR_ASSERT( controlButtonObject != NULL ); OVR_UNUSED( controlButtonObject ); }
//---------------------------------------------------------------------------------- bool Helper_ProcessFace(IGameMesh * gM, unsigned int Index, const AffineParts & PRS, const Matrix3 & world_to_obj, MatFaceMapType & matface_map, TriMapType & tri_map, unsigned int & MaxFaceIdx) { FaceEx *pFace = gM->GetFace(Index); IGameMaterial *pIGMat = gM->GetMaterialFromFace(Index); bool HasTexVerts = gM->GetNumberOfTexVerts() ? true : false; bool HasCVerts = gM->GetNumberOfColorVerts() ? true : false; unsigned int smg_id = pFace->smGrp; // smooth group unsigned int mat_id = ExporterMAX::GetExporter()->FindMaterialIdx(pIGMat); IGameSkin *skin = NULL; const int numMod = gM->GetNumModifiers(); if (numMod > 0) { for (int i = 0; i < numMod; i++) // check for skin modifier { IGameModifier *pM = gM->GetIGameModifier(i); if (pM->IsSkin()) { skin = (IGameSkin*)pM; // skin modifier } } } mesh_opt * m_opt = NULL; // lets sort by material and find the corresponding mesh_opt MatFaceMapIt it_matfacemap = matface_map.find(mat_id); if (it_matfacemap == matface_map.end()) // no corresponding mesh, allocate new face holder { m_opt = new mesh_opt(); matface_map.insert(MatFaceMapPair(mat_id, m_opt)); } else { m_opt = (*it_matfacemap).second; } for (int j = 0; j < 3; ++j) // build the face { vert_opt face; unsigned int idx; unsigned int ori_face_idx = pFace->vert[j]; // get index into the vertex array unsigned int face_idx = ori_face_idx; bool create_face = false; // build the face as expected face.smg_id = smg_id; // smooth group if (HasTexVerts) { idx = pFace->texCoord[j]; // get index into the standard mapping channel if (idx != BAD_IDX) { face.t.x = gM->GetTexVertex(idx).x; face.t.y = gM->GetTexVertex(idx).y; } } if (HasCVerts) { idx = pFace->color[j]; face.c.x = gM->GetColorVertex(idx).x; // get vertex color face.c.y = gM->GetColorVertex(idx).y; face.c.z = gM->GetColorVertex(idx).z; face.c.w = 1.f; } else { face.c = Vector4f(1.f, 1.f, 1.f, 1.f); } Tab<int> mapNums = gM->GetActiveMapChannelNum(); face.num_tmaps = mapNums.Count(); if (face.num_tmaps) { face.tmaps = new Vector[face.num_tmaps]; for (size_t k = 0; k < face.num_tmaps; ++k) { unsigned long mapfaceidx[3]; gM->GetMapFaceIndex(mapNums[k], Index, &mapfaceidx[0]); idx = mapfaceidx[j]; face.tmaps[k].x = gM->GetMapVertex(mapNums[k], idx).x; face.tmaps[k].y = gM->GetMapVertex(mapNums[k], idx).y; face.tmaps[k].z = gM->GetMapVertex(mapNums[k], idx).z; } } // try to find in origin array FaceMapIt it_face_map = m_opt->face_map.find(face_idx); // get face map iter if (it_face_map == m_opt->face_map.end()) // if not find such create anyway { create_face = true; } else { if (is_matching((*it_face_map).second, face) == false) // check find vertex not matching { bool found = false; // process vertex multi map std::pair<FaceMMapIt,FaceMMapIt> pair_mmap = m_opt->face_mmap.equal_range(ori_face_idx); FaceMMapIt it_face_mmap = pair_mmap.first; while (it_face_mmap != pair_mmap.second && found == false) { idxvert_opt & idxface = (*it_face_mmap).second; if (is_matching(idxface.face, face)) { face_idx = idxface.new_idx; found = true; } ++it_face_mmap; } if (found == false) { create_face = true; ++MaxFaceIdx; // increment max index and face_idx = MaxFaceIdx; // set index is out of bounds of origin 3DMax's index range } } } if (create_face) { if (skin) { std::vector<w_offset> w_offsets; for (int k = 0; k < skin->GetNumberOfBones(ori_face_idx); ++k) { /* if (skin->GetWeight(ori_face_idx, k) > m_eps) { w_offset w; w.weight = skin->GetWeight(ori_face_idx, k); _BoneObject * Bone = ExporterMAX::GetExporter()->Skeleton.AddMaxBone(skin->GetIGameBone(ori_face_idx, k), skin->GetIGameBone(ori_face_idx, k)->GetNodeID()); assert(Bone != NULL); w.bone_id = Bone->GetID(); w_offsets.push_back(w); }*/ } // std::sort(w_offsets.begin(), w_offsets.end(), heavier); int ILeft = 0; for (size_t l = 0; l < w_offsets.size() && l < 4; ++l, ++ILeft) { w_offset & w = w_offsets[l]; face.weights[l] = w.weight; face.bones[l] = w.bone_id; } for (; ILeft < 4; ++ILeft) { face.weights[ILeft] = 0.f; face.bones[ILeft] = BAD_IDX; } // check for valid weights... float w_sum = 0.f; for (int l = 0; l < 4; ++l) { w_sum += face.weights[l]; } if ((w_sum < m_one - m_eps) || (w_sum > m_one + m_eps)) { for (int l = 0; l < 4; ++l) // renormalizing... face.weights[l] /= w_sum; } } Point3 v_world = gM->GetVertex(ori_face_idx); Point3 v_obj = v_world; // * world_to_obj; face.v.x = v_obj.x; // * PRS.k.x * PRS.f; face.v.y = v_obj.z; // * PRS.k.z * PRS.f; face.v.z = v_obj.y; // * PRS.k.y * PRS.f; // add the vertex and store its new idx face.face_idx = m_opt->count; m_opt->face_map.insert(FaceMapPair(face_idx, face)); if (ori_face_idx != face_idx) // store the newly created and duplicated independently { idxvert_opt idxface(face_idx, face);// store new face m_opt->face_mmap.insert(FaceMMapPair(ori_face_idx, idxface)); // but store key as a original } m_opt->count++; } // add the face indices... TriMapIt it = tri_map.find(mat_id); if (it != tri_map.end()) { (*it).second->push_back(face_idx); } else { IdxType * idx_type = new IdxType; idx_type->push_back(face_idx); tri_map.insert(TriMapPair(mat_id, idx_type)); } } return true; }
void ResumeMovieView::CreateMenu( App * app, OvrVRMenuMgr & menuMgr, BitmapFont const & font ) { Menu = VRMenu::Create( "ResumeMoviePrompt" ); Vector3f fwd( 0.0f, 0.0f, 1.0f ); Vector3f up( 0.0f, 1.0f, 0.0f ); Vector3f defaultScale( 1.0f ); Array< VRMenuObjectParms const * > parms; VRMenuFontParms fontParms( true, true, false, false, false, 1.3f ); Quatf orientation( Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ); Vector3f centerPos( 0.0f, 0.0f, 0.0f ); VRMenuObjectParms centerRootParms( VRMENU_CONTAINER, Array< VRMenuComponent* >(), VRMenuSurfaceParms(), "CenterRoot", Posef( orientation, centerPos ), Vector3f( 1.0f, 1.0f, 1.0f ), fontParms, ID_CENTER_ROOT, VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( ¢erRootParms ); Menu->InitWithItems( menuMgr, font, 0.0f, VRMenuFlags_t(), parms ); parms.Clear(); // the centerroot item will get touch relative and touch absolute events and use them to rotate the centerRoot menuHandle_t centerRootHandle = Menu->HandleForId( menuMgr, ID_CENTER_ROOT ); VRMenuObject * centerRoot = menuMgr.ToObject( centerRootHandle ); OVR_ASSERT( centerRoot != NULL ); // ============================================================================== // // title // { Posef panelPose( Quatf( up, 0.0f ), Vector3f( 0.0f, 2.2f, -3.0f ) ); VRMenuObjectParms p( VRMENU_STATIC, Array< VRMenuComponent* >(), VRMenuSurfaceParms(), Strings::ResumeMenu_Title, panelPose, defaultScale, fontParms, VRMenuId_t( ID_TITLE.Get() ), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &p ); Menu->AddItems( menuMgr, font, parms, centerRootHandle, false ); parms.Clear(); } // ============================================================================== // // options // Array<const char *> options; options.PushBack( Strings::ResumeMenu_Resume ); options.PushBack( Strings::ResumeMenu_Restart ); Array<const char *> icons; icons.PushBack( "assets/resume.png" ); icons.PushBack( "assets/restart.png" ); Array<PanelPose> optionPositions; optionPositions.PushBack( PanelPose( Quatf( up, 0.0f / 180.0f * Mathf::Pi ), Vector3f( -0.5f, 1.7f, -3.0f ), Vector4f( 1.0f, 1.0f, 1.0f, 1.0f ) ) ); optionPositions.PushBack( PanelPose( Quatf( up, 0.0f / 180.0f * Mathf::Pi ), Vector3f( 0.5f, 1.7f, -3.0f ), Vector4f( 1.0f, 1.0f, 1.0f, 1.0f ) ) ); int borderWidth = 0, borderHeight = 0; GLuint borderTexture = LoadTextureFromApplicationPackage( "assets/resume_restart_border.png", TextureFlags_t( TEXTUREFLAG_NO_DEFAULT ), borderWidth, borderHeight ); for ( int i = 0; i < optionPositions.GetSizeI(); ++i ) { ResumeMovieComponent * resumeMovieComponent = new ResumeMovieComponent( this, i ); Array< VRMenuComponent* > optionComps; optionComps.PushBack( resumeMovieComponent ); VRMenuSurfaceParms panelSurfParms( "", borderTexture, borderWidth, borderHeight, SURFACE_TEXTURE_ADDITIVE, 0, 0, 0, SURFACE_TEXTURE_MAX, 0, 0, 0, SURFACE_TEXTURE_MAX ); Posef panelPose( optionPositions[ i ].Orientation, optionPositions[ i ].Position ); VRMenuObjectParms * p = new VRMenuObjectParms( VRMENU_BUTTON, optionComps, panelSurfParms, options[ i ], panelPose, defaultScale, fontParms, VRMenuId_t( ID_OPTIONS.Get() + i ), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( p ); Menu->AddItems( menuMgr, font, parms, centerRootHandle, false ); DeletePointerArray( parms ); parms.Clear(); // add icon menuHandle_t optionHandle = centerRoot->ChildHandleForId( menuMgr, VRMenuId_t( ID_OPTIONS.Get() + i ) ); VRMenuObject * optionObject = menuMgr.ToObject( optionHandle ); OVR_ASSERT( optionObject != NULL ); int iconWidth = 0, iconHeight = 0; GLuint iconTexture = LoadTextureFromApplicationPackage( icons[ i ], TextureFlags_t( TEXTUREFLAG_NO_DEFAULT ), iconWidth, iconHeight ); VRMenuSurfaceParms iconSurfParms( "", iconTexture, iconWidth, iconHeight, SURFACE_TEXTURE_DIFFUSE, 0, 0, 0, SURFACE_TEXTURE_MAX, 0, 0, 0, SURFACE_TEXTURE_MAX ); Bounds3f textBounds = optionObject->GetTextLocalBounds( font ); optionObject->SetTextLocalPosition( Vector3f( iconWidth * VRMenuObject::DEFAULT_TEXEL_SCALE * 0.5f, 0.0f, 0.0f ) ); Posef iconPose( optionPositions[ i ].Orientation, optionPositions[ i ].Position + Vector3f( textBounds.GetMins().x, 0.0f, 0.01f ) ); p = new VRMenuObjectParms( VRMENU_STATIC, Array< VRMenuComponent* >(), iconSurfParms, NULL, iconPose, defaultScale, fontParms, VRMenuId_t( ID_OPTION_ICONS.Get() + i ), VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_ALL ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( p ); Menu->AddItems( menuMgr, font, parms, centerRootHandle, false ); DeletePointerArray( parms ); parms.Clear(); menuHandle_t iconHandle = centerRoot->ChildHandleForId( menuMgr, VRMenuId_t( ID_OPTION_ICONS.Get() + i ) ); resumeMovieComponent->Icon = menuMgr.ToObject( iconHandle ); } Cinema.app->GetGuiSys().AddMenu( Menu ); }
void Divine::onBeginEvent(Geoscape* geoscape) { castBoogieEvent(); castFestivalEvent(); castClimbingEvent(); castSmokeballEvent(); castCommunityEvent(); // if player isn't in home location and isn't travelling if( geoscape->getPlayerLocation() && geoscape->getPlayerLocation()->getDatabaseId() != 0 ) { // location info database::LocationInfo* info = database::LocationInfo::getRecord( geoscape->getPlayerLocation()->getDatabaseId() ); // home location travelling cost Vector2f currentCoords = geoscape->getPlayerLocation()->getLocationCoords(); Vector2f targetCoords = geoscape->getHomeLocation()->getLocationCoords(); float targetDistance = ( targetCoords - currentCoords ).length(); targetDistance = targetDistance * 40075.696f / geoscape->getWindow()->getPanel()->getRect().getWidth(); float referenceCost = 0.05f; float targetCost = targetDistance * referenceCost; float referenceTime = 0.1f; float targetTime = targetDistance * referenceTime; // check we have enought money to stay in location if( targetCost + info->stayFee < _career->getVirtues()->evolution.funds ) { // pay fee _career->getVirtues()->evolution.funds -= info->stayFee; } else { // travel to home location // remove player from location unsigned int departureId = geoscape->getPlayerLocation()->getDatabaseId(); geoscape->getPlayerLocation()->setPlayer( false ); // decrease funds _career->getVirtues()->evolution.funds -= targetCost; // add event _career->addEvent( new Travel( _career, departureId, 0, targetTime ) ); // message geoscape->addHistory( Gameplay::iLanguage->getUnicodeString(293), Vector4f( 1,0.25,0.25,1 ) ); } } // simulate market dynamics unsigned int maxTransactions = 10; // simulate buying unsigned int numTransactions = getCore()->getRandToolkit()->getUniformInt() % maxTransactions; while( numTransactions && geoscape->getMarketSize() ) { // buy random gear geoscape->removeGearFromMarket( getCore()->getRandToolkit()->getUniformInt() % geoscape->getMarketSize() ); numTransactions--; } // simulate selling numTransactions = getCore()->getRandToolkit()->getUniformInt() % maxTransactions; while( numTransactions ) { // sell random gear Gear gear = geoscape->generateGear( getCore()->getRandToolkit()->getUniform( 0, 1 ) > 0.75f ); if( gear.isTradeable() ) geoscape->addGearToMarket( gear ); numTransactions--; } }
bool Transform::any_intersect(const Ray& r, Hit& h, float tmin) { return o->any_intersect(Ray((mInverse*Vector4f(r.getOrigin(), 1)).xyz(), mInverse3*r.getDirection()), h, tmin); }
EKFSmoother::EKFSmoother( int n, float q, float r ) : EKFSmoother( n, Vector4f( q, q, q, q ), Vector4f( r, r, r, r ) ) { }
void AppLocal::DrawEyeViewsPostDistorted( Matrix4f const & centerViewMatrix, const int numPresents ) { // update vr lib systems after the app frame, but before rendering anything GetGuiSys().Frame( this, vrFrame, GetVRMenuMgr(), GetDefaultFont(), GetMenuFontSurface() ); GetGazeCursor().Frame( this->lastViewMatrix, vrFrame.DeltaSeconds ); if ( ShowFPS ) { static double LastFrameTime = TimeInSeconds(); static double AccumulatedFrameInterval = 0.0; static int NumAccumulatedFrames = 0; static float LastFrameRate = 60.0f; double currentFrameTime = TimeInSeconds(); double frameInterval = currentFrameTime - LastFrameTime; AccumulatedFrameInterval += frameInterval; NumAccumulatedFrames++; if ( NumAccumulatedFrames > FPS_NUM_FRAMES_TO_AVERAGE ) { double interval = ( AccumulatedFrameInterval / NumAccumulatedFrames ); // averaged AccumulatedFrameInterval = 0.0; NumAccumulatedFrames = 0; LastFrameRate = 1.0f / float( interval > 0.000001 ? interval : 0.00001 ); } fontParms_t fontParms; fontParms.CenterHoriz = true; fontParms.Billboard = true; fontParms.TrackRoll = true; const Vector3f viewPos( GetViewMatrixPosition( centerViewMatrix ) ); const Vector3f viewFwd( GetViewMatrixForward( centerViewMatrix ) ); const Vector3f textPos( viewPos + viewFwd * 1.5f ); GetWorldFontSurface().DrawTextBillboarded3Df( GetDefaultFont(), fontParms, textPos, 0.0025f, Vector4f( 1.0f, 0.0f, 0.0f, 1.0f ), "%.1f fps", LastFrameRate ); LastFrameTime = currentFrameTime; } if ( InfoTextEndFrame >= vrFrame.FrameNumber ) { fontParms_t fontParms; fontParms.CenterHoriz = true; fontParms.Billboard = true; fontParms.TrackRoll = true; const Vector3f viewPos( GetViewMatrixPosition( centerViewMatrix ) ); const Vector3f viewFwd( GetViewMatrixForward( centerViewMatrix ) ); const Vector3f textPos( viewPos + viewFwd * 1.5f ); GetWorldFontSurface().DrawTextBillboarded3Df( GetDefaultFont(), fontParms, textPos, 0.0025f, Vector4f( 1.0f, 1.0f, 1.0f, 1.0f ), InfoText.ToCStr() ); } GetMenuFontSurface().Finish( centerViewMatrix ); GetWorldFontSurface().Finish( centerViewMatrix ); GetVRMenuMgr().Finish( centerViewMatrix ); // Increase the fov by about 10 degrees if we are not holding 60 fps so // there is less black pull-in at the edges. // // Doing this dynamically based just on time causes visible flickering at the // periphery when the fov is increased, so only do it if minimumVsyncs is set. const float fovDegrees = hmdInfo.SuggestedEyeFov + ( ( ( SwapParms.MinimumVsyncs > 1 ) || ovr_GetPowerLevelStateThrottled() ) ? 10.0f : 0.0f ) + ( ( !showVignette ) ? 5.0f : 0.0f ); // DisplayMonoMode uses a single eye rendering for speed improvement // and / or high refresh rate double-scan hardware modes. const int numEyes = renderMonoMode ? 1 : 2; // Flush out and report any errors GL_CheckErrors("FrameStart"); if ( drawCalibrationLines && calibrationLinesDrawn ) { // doing a time warp test, don't generate new images LOG( "drawCalibrationLines && calibrationLinesDrawn" ); } else { // possibly change the buffer parameters EyeTargets->BeginFrame( vrParms ); for (int eye = 0; eye < numEyes; eye++) { EyeTargets->BeginRenderingEye( eye ); // Call back to the app for drawing. const Matrix4f mvp = appInterface->DrawEyeView( eye, fovDegrees ); DrawActivity( mvp ); DrawPassThroughCamera( fovDegrees, vrFrame.PoseState.Pose.Orientation ); GetVRMenuMgr().RenderSubmitted( mvp.Transposed() ); GetMenuFontSurface().Render3D( GetDefaultFont(), mvp.Transposed() ); GetWorldFontSurface().Render3D( GetDefaultFont(), mvp.Transposed() ); glDisable( GL_DEPTH_TEST ); glDisable( GL_CULL_FACE ); // Optionally draw thick calibration lines into the texture, // which will be overlayed by the thinner origin cross when // distorted to the window. if ( drawCalibrationLines ) { EyeDecorations.DrawEyeCalibrationLines(fovDegrees, eye); calibrationLinesDrawn = true; } else { calibrationLinesDrawn = false; } DrawDialog( mvp ); GetGazeCursor().Render( eye, mvp ); GetDebugLines().Render( mvp.Transposed() ); if ( showVignette ) { // Draw a thin vignette at the edges of the view so clamping will give black // This will not be reflected correctly in overlay planes. // EyeDecorations.DrawEyeVignette(); EyeDecorations.FillEdge( vrParms.resolution, vrParms.resolution ); } EyeTargets->EndRenderingEye( eye ); } } // This eye set is complete, use it now. if ( numPresents > 0 ) { const CompletedEyes eyes = EyeTargets->GetCompletedEyes(); for ( int eye = 0 ; eye < TimeWarpParms::MAX_WARP_EYES ; eye++ ) { const Matrix4f proj = Matrix4f::PerspectiveRH( DegreeToRad(fovDegrees), 1.0f, 1, 100); SwapParms.Images[eye][0].TexCoordsFromTanAngles = TanAngleMatrixFromProjection( proj ); SwapParms.Images[eye][0].TexId = eyes.Textures[renderMonoMode ? 0 : eye ]; SwapParms.Images[eye][0].Pose = SensorForNextWarp.Predicted; } ovr_WarpSwap( OvrMobile, &SwapParms ); } }
void PrimitivesInspector::PrimitivesTab::assembleList(){ for (int i=0;i<(int)mine->listButton.size();i++){ mine->listButton[i]->remove(); } mine->listButton.clear(); mine->listName.clear(); mine->listProp.clear(); mine->listIcon.clear(); if (mine->scrollBar){ mine->scrollBar->remove(); mine->scrollBar=NULL; } cout << "creating list..." << endl; //a plane //a character //a camera //a sprite //a light mine->listName.push_back("Character"); mine->listProp.push_back("9Character"); mine->listIcon.push_back("icon_character"); mine->listName.push_back("Camera"); mine->listProp.push_back("11CameraActor"); mine->listIcon.push_back("icon_camera"); mine->listName.push_back("Plane"); mine->listProp.push_back("13SkeletalActor"); mine->listIcon.push_back("icon_plane"); mine->listName.push_back("Cube"); mine->listProp.push_back("13SkeletalActor"); mine->listIcon.push_back("icon_cube"); mine->listName.push_back("Sprite"); mine->listProp.push_back("13SkeletalActor"); mine->listIcon.push_back("icon_target"); mine->listName.push_back("PointPatch"); mine->listProp.push_back("13SkeletalActor"); mine->listIcon.push_back("icon_pointPatch"); //--- test video actor #ifdef TARGET_WIN32 mine->listName.push_back("VideoTexture"); mine->listProp.push_back("17VideoTextureActor"); mine->listIcon.push_back("icon_texture"); #endif mine->listName.push_back("Light"); mine->listProp.push_back("8MsbLight"); mine->listIcon.push_back("icon_light"); for (int i=0; i<(int)mine->listProp.size(); i++){ mine->sceneData->actorInfo["17CreateActorButton"].actorReference->create(); mine->listButton.push_back(mine->sceneData->buttonList.back()); mine->listButton[i]->name=mine->listName[i]; mine->listButton[i]->buttonProperty=mine->listProp[i]; mine->listButton[i]->setTextureID(mine->listIcon[i]); mine->listButton[i]->level=mine->level+1; mine->listButton[i]->bDrawName=true; mine->listButton[i]->color=Vector4f(0.8,0.8,0.8,1.0); mine->listButton[i]->bPermanent=true; mine->listButton[i]->bDragable=true; mine->listButton[i]->parent=mine; mine->listButton[i]->drawNameOffset.y=mine->listHeight/2.0; if (mine->listWidth>0) mine->listButton[i]->scale.x=mine->listWidth; //leave room for name beneath icon if (mine->listHeight>0) mine->listButton[i]->scale.y=mine->listHeight-16.0; mine->listButton[i]->setup(); mine->placeButton(i,i); //set this because we want to drag buttons around! mine->listButton[i]->initialLocation=mine->listButton[i]->location; } cout << "PrimitivesInspector: our Button list is: "<< mine->listButton.size() <<" elements long..." << endl; if (mine->listButton.size()>0) mine->listSize.y=mine->listButton[mine->listButton.size()-1]->location.y+mine->listButton[mine->listButton.size()-1]->scale.y - mine->location.y; else mine->listSize.y=0; }
void PrimitivesInspector::NodeTab::assembleList(){ for (int i=0;i<(int)mine->listButton.size();i++){ mine->listButton[i]->remove(); } mine->listButton.clear(); mine->listName.clear(); mine->listProp.clear(); mine->listIcon.clear(); if (mine->scrollBar){ mine->scrollBar->remove(); mine->scrollBar=NULL; } cout << "creating list..." << endl; mine->listName.push_back("RootNode"); mine->listName.push_back("WaitTime"); mine->listName.push_back("WalkTo"); mine->listName.push_back("KeyInput"); mine->listName.push_back("SwitchCamera"); mine->listName.push_back("SetAnimation"); mine->listName.push_back("StopAnim"); mine->listName.push_back("WaitForEvent"); mine->listName.push_back("TriggerEvent"); mine->listName.push_back("ConsoleCommand"); mine->listName.push_back("Interpolate"); mine->listName.push_back("SetWalkTarget"); mine->listName.push_back("SetHidden"); mine->listName.push_back("TriggerActor"); mine->listName.push_back("AttachTo"); mine->listName.push_back("PerformAction"); mine->listName.push_back("SetProperty"); mine->listName.push_back("SetBackground"); mine->listName.push_back("MorphSpriteMesh"); mine->listName.push_back("load new"); mine->listProp.push_back("8RootNode"); mine->listProp.push_back("16WaitForTimerNode"); mine->listProp.push_back("10WalkToNode"); mine->listProp.push_back("12KeyInputNode"); mine->listProp.push_back("16SwitchCameraNode"); mine->listProp.push_back("16SetAnimationNode"); mine->listProp.push_back("12StopAnimNode"); mine->listProp.push_back("16WaitForEventNode"); mine->listProp.push_back("16TriggerEventNode"); mine->listProp.push_back("18ConsoleCommandNode"); mine->listProp.push_back("15InterpolateNode"); mine->listProp.push_back("17SetWalkTargetNode"); mine->listProp.push_back("13SetHiddenNode"); mine->listProp.push_back("16TriggerActorNode"); mine->listProp.push_back("12AttachToNode"); mine->listProp.push_back("17PerformActionNode"); mine->listProp.push_back("15SetPropertyNode"); mine->listProp.push_back("17SetBackgroundNode"); mine->listProp.push_back("19MorphSpriteMeshNode"); mine->listProp.push_back("8LoadNode"); int i; for (i=0; i<(int)mine->listProp.size(); i++){ mine->sceneData->actorInfo["16CreateNodeButton"].actorReference->create(); mine->listButton.push_back(mine->sceneData->buttonList.back()); mine->listButton[i]->name=mine->listName[i]; mine->listButton[i]->buttonProperty=mine->listProp[i]; mine->listButton[i]->setTextureID("icon_nodeMenu"); mine->listButton[i]->level=mine->level+1; mine->listButton[i]->bDrawName=true; mine->listButton[i]->tooltip=mine->listName[i]; mine->listButton[i]->color=Vector4f(1,1,1,1.0); mine->listButton[i]->bPermanent=true; mine->listButton[i]->bDragable=true; mine->listButton[i]->drawNameOffset.y=mine->listHeight/2.0; if (mine->listWidth>0) mine->listButton[i]->scale.x=mine->listWidth; //leave room for name beneath icon if (mine->listHeight>0) mine->listButton[i]->scale.y=mine->listHeight-16.0; mine->listButton[i]->setup(); mine->placeButton(i,i); //set this because we want to drag buttons around! mine->listButton[i]->initialLocation=mine->listButton[i]->location; } //add udpInput as non-node at the end mine->listName.push_back("UDPInput"); mine->listProp.push_back("8UdpInput"); mine->sceneData->actorInfo["17CreateActorButton"].actorReference->create(); mine->listButton.push_back(mine->sceneData->buttonList.back()); mine->listButton[i]->name=mine->listName[i]; mine->listButton[i]->buttonProperty=mine->listProp[i]; mine->listButton[i]->setTextureID("icon_base"); mine->listButton[i]->level=mine->level+1; mine->listButton[i]->bDrawName=true; mine->listButton[i]->color=Vector4f(1,1,1,1.0); mine->listButton[i]->bPermanent=true; mine->listButton[i]->bDragable=true; mine->listButton[i]->drawNameOffset.y=mine->listHeight/2.0; if (mine->listWidth>0) mine->listButton[i]->scale.x=mine->listWidth; //leave room for name beneath icon if (mine->listHeight>0) mine->listButton[i]->scale.y=mine->listHeight-16.0; mine->listButton[i]->setup(); mine->placeButton(i,i); //set this because we want to drag buttons around! mine->listButton[i]->initialLocation=mine->listButton[i]->location; cout << "NodeInspector: our Button list is: "<< mine->listButton.size() <<" elements long..." << endl; if (mine->listButton.size()>0) mine->listSize.y=mine->listButton[mine->listButton.size()-1]->location.y+mine->listButton[mine->listButton.size()-1]->scale.y - mine->location.y; else mine->listSize.y=0; }
void GLAssimpMeshBinding::load(const aiScene *scene, const aiMesh *mesh) { // only process if we haven't already loaded this - otherwise is just GL reload if (!this->mesh) { Property *prop = btGetContext()->appProperties->get("debug_assimp"); if (prop) { debugAssimp = prop->getBoolValue(); } this->mesh = mesh; hasBones = (mesh->mNumBones > 0); if (hasBones) { vertSkinnedAtts = new GLAssimpSkinnedMeshVertex[mesh->mNumVertices]; } else { vertBasicAtts = new GLAssimpMeshVertex[mesh->mNumVertices]; } if (hasBones) { for (U32 i = 0; i < mesh->mNumVertices; i++) { aiVector3D vert = mesh->mVertices[i]; aiVector3D normal = mesh->mNormals[i]; aiVector3D uv = mesh->mTextureCoords[0][i]; vertSkinnedAtts[i].position = Vector3f(vert.x, vert.y, vert.z); vertSkinnedAtts[i].normal = Vector3f(normal.x, normal.y, normal.z); vertSkinnedAtts[i].uv = Vector2f(uv.x, uv.y); vertSkinnedAtts[i].bones = Vector4b(0, 0, 0, 0); vertSkinnedAtts[i].weights = Vector4f(0, 0, 0, 0); } U32 *weightCounts = new U32[mesh->mNumVertices]; memset(weightCounts, 0, mesh->mNumVertices * 4); BOOL32 discardedWeights = FALSE; for (U8 i = 0; i < (U8)mesh->mNumBones; i++) { aiBone *bone = mesh->mBones[i]; for (U32 j = 0; j < bone->mNumWeights; j++) { U32 vertIdx = bone->mWeights[j].mVertexId; F32 weight = bone->mWeights[j].mWeight; U32 weightNum = weightCounts[vertIdx]; if (weightNum < 4) { vertSkinnedAtts[vertIdx].bones[weightNum] = i; vertSkinnedAtts[vertIdx].weights[weightNum] = weight; weightCounts[vertIdx]++; } else { discardedWeights = TRUE; } } } delete [] weightCounts; if (discardedWeights) { logmsg("AssimpBind Warning: Too many bone weights - discarding!"); } } else { for (U32 i = 0; i < mesh->mNumVertices; i++) { aiVector3D vert = mesh->mVertices[i]; aiVector3D normal = mesh->mNormals[i]; aiVector3D uv = mesh->mTextureCoords[0][i]; vertBasicAtts[i].position = Vector3f(vert.x, vert.y, vert.z); vertBasicAtts[i].normal = Vector3f(normal.x, normal.y, normal.z); vertBasicAtts[i].uv = Vector2f(uv.x, uv.y); } } loadMaterials(scene->mMaterials[mesh->mMaterialIndex]); } U16 *faceIndices = new U16[this->mesh->mNumFaces * 3]; for (U32 i = 0; i < this->mesh->mNumFaces; i++) { aiFace face = this->mesh->mFaces[i]; faceIndices[i*3] = face.mIndices[0]; faceIndices[i*3+1] = face.mIndices[1]; faceIndices[i*3+2] = face.mIndices[2]; } loadGeometry(this->mesh, faceIndices); delete [] faceIndices; }