void kore::Camera::updateFrustumPlanes() { // If the camera's projection matrix is an orthogonal projection, // the frustum planes have to be derived // from the general projection matrix if (_bIsOrtho) { glm::mat4 projT = glm::transpose(_matProjection); _v4FrustumPlanesVS[ PLANE_NEAR ] = projT[3] + projT[2]; _v4FrustumPlanesVS[ PLANE_FAR ] = projT[3] - projT[2]; _v4FrustumPlanesVS[ PLANE_LEFT ] = projT[3] + projT[0]; _v4FrustumPlanesVS[ PLANE_RIGHT ] = projT[3] - projT[0]; _v4FrustumPlanesVS[ PLANE_BOTTOM ] = projT[3] + projT[1]; _v4FrustumPlanesVS[ PLANE_TOP ] = projT[3] - projT[1]; // The normals in the plane-vectors (N.x, N.y, N.z, D) have to be normalized glm::vec3 v3N; for (unsigned int i = 0; i < 6; ++i) { v3N = glm::normalize(glm::vec3(_v4FrustumPlanesVS[i])); _v4FrustumPlanesVS[ i ].x = v3N.x; _v4FrustumPlanesVS[ i ].y = v3N.y; _v4FrustumPlanesVS[ i ].z = v3N.z; } } else { // If the camera's projection matrix is a perspective projection, // the view-space frustum planes can be // determined by the proj-parameters of the camera // (more efficient this way) float fe1 = glm::sqrt(_fFocalLength * _fFocalLength + 1); float fea = glm::sqrt(_fFocalLength * _fFocalLength + getAspectRatio() * getAspectRatio()); _v4FrustumPlanesVS[PLANE_NEAR] = glm::vec4(0.0f, 0.0f, -1.0f, -_fNear); _v4FrustumPlanesVS[PLANE_FAR] = glm::vec4(0.0f, 0.0f, 1.0f, _fFar); _v4FrustumPlanesVS[PLANE_LEFT] = glm::vec4(_fFocalLength / fe1, 0.0f, -1.0f / fe1, 0.0f); _v4FrustumPlanesVS[PLANE_RIGHT] = glm::vec4(-_fFocalLength / fe1, 0.0f, -1.0f / fe1, 0.0f); _v4FrustumPlanesVS[PLANE_BOTTOM] = glm::vec4(0.0f, _fFocalLength / fea, -getAspectRatio() / fea, 0.0f); _v4FrustumPlanesVS[PLANE_TOP] = glm::vec4(0.0f, -_fFocalLength / fea, -getAspectRatio() / fea, 0.0f); } }
int VideoFormat::dump(DumpContext& dc) { // throws IOException dc.indent(); dc.getPs().print("VideoFormat\n"); dc.increaseIndent(); int retVal= 0; // write horizontalLine dc.indent(); dc.getPs().print("horizontalLine="); dc.getPs().println((long)horizontalLine); // write verticalline dc.indent(); dc.getPs().print("verticalline="); dc.getPs().println((long)verticalline); // write frameRate dc.indent(); dc.getPs().print("frameRate="); dc.getPs().println((long)frameRate); // write bf1 { dc.indent(); dc.getPs().print("aspectRatio: "); dc.getPs().printlnBin(getAspectRatio(),2); dc.indent(); dc.getPs().print("progInterType: "); dc.getPs().printlnBin(getProgInterType(),1); dc.indent(); dc.getPs().print("reserved: "); dc.getPs().printlnBin(getReserved(),5); } dc.decreaseIndent(); return retVal; }
std::tuple<int, int> QS::RealTimeVisualization::getWindowDimensions() noexcept { const float scaleFactor = 0.9; const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); float maxHeight = mode->height * scaleFactor; float maxWidth = mode->width * scaleFactor; // This finds the window size that best fits into the maximums above while // still maintaining the aspect ratio of the world. There are probably more // efficient ways to do this, but I can't think of one and the loop shouldn't // ever be more than a few thousand iterations, which isn't bad at all. float aspectRatio = getAspectRatio(); float width = aspectRatio; float height = 1.0; while (width < maxWidth && height < maxHeight) { height++; width = height * aspectRatio; } myWindowWidth = static_cast<int>(width); myWindowHeight = static_cast<int>(height); return std::make_tuple(myWindowWidth, myWindowHeight); }
void TCompCamera::renderInMenu() { float fov_in_rad = getFov(); float znear = getZNear(); float zfar = getZFar(); float ar = getAspectRatio(); bool changed = false; //float fov_in_deg = rad2deg(fov_in_rad); //if (ImGui::SliderFloat("Fov", &fov_in_deg, 30.f, 110.f)) { // changed = true; // fov_in_rad = deg2rad(fov_in_deg); //} if (!isOrtho()) { float fov_in_deg = rad2deg(fov_in_rad); if (ImGui::DragFloat("Fov", &fov_in_deg, 0.1f, 1.f, 120.f)) { changed = true; fov_in_rad = deg2rad(clamp(fov_in_deg, 1.f, 120.f)); } } changed |= ImGui::DragFloat("ZNear", &znear, 0.01f, 0.01f); changed |= ImGui::DragFloat("ZFar", &zfar, 0.01f, 1.f, 1000.f); if (changed) setProjection(fov_in_rad, znear, zfar); if (ImGui::SliderFloat("a/r", &ar, 0.f, 10.f)) { //setAspectRatio(ar); } }
void Camera::computeProjectionMatrix() { switch (m_type) { case CameraType::PERSPECTIVE: { const float f = 1.0 / tan(m_fieldOfView / 2.0); m_projectionMatrix(0, 0) = f / getAspectRatio(); m_projectionMatrix(1, 1) = f; m_projectionMatrix(2, 2) = (m_nearPlane + m_farPlane) / (m_nearPlane - m_farPlane); m_projectionMatrix(3, 2) = -1.0; m_projectionMatrix(2, 3) = 2.0 * m_nearPlane * m_farPlane / (m_nearPlane - m_farPlane); m_projectionMatrix(3, 3) = 0.0; // same as gluPerspective( 180.0*fieldOfView()/M_PI, aspectRatio(), zNear(), zFar() ); break; } case CameraType::ORTHOGRAPHIC: { m_projectionMatrix(0, 0) = 1.0 / static_cast<float>(m_screenWidth); m_projectionMatrix(1, 1) = 1.0 / static_cast<float>(m_screenHeight); m_projectionMatrix(2, 2) = -2.0 / (m_farPlane - m_nearPlane); m_projectionMatrix(3, 2) = 0.0; m_projectionMatrix(2, 3) = (m_farPlane + m_nearPlane) / (m_nearPlane - m_farPlane); m_projectionMatrix(3, 3) = 1.0; // same as glOrtho( -w, w, -h, h, zNear(), zFar() ); break; } } }
void MeshGame::initialize() { // Display the gameplay splash screen for at least 1 second. displayScreen(this, &MeshGame::drawSplash, NULL, 1000L); // Load the font _font = Font::create("res/ui/arial.gpb"); // Load the scene from file _scene = Scene::load("res/mesh.scene"); // Get the duck node _modelNode = _scene->findNode("duck"); _scene = Scene::load("res/room1.scene"); // Find the light node Node* lightNode = _scene->findNode("directionalLight1"); // Bind the light node's direction into duck's material. _modelNode->getModel()->getMaterial()->getParameter("u_directionalLightColor[0]")->setValue(lightNode->getLight()->getColor()); _modelNode->getModel()->getMaterial()->getParameter("u_directionalLightDirection[0]")->bindValue(lightNode, &Node::getForwardVectorView); // Update the aspect ratio for our scene's camera to match the current device resolution _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); // Create the grid and add it to the scene. Model *model = createGridModel(); _scene->addNode("grid")->setModel(model); model->release(); }
bool Utils::isPad() { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) return IOSUtils::isIPad(); #else return getAspectRatio() < 1.4f; #endif }
void Frustum::setNearFarDist( F32 nearDist, F32 farDist ) { if( mNearDist == nearDist && mFarDist == farDist ) return; // Recalculate the frustum. MatrixF xfm( mTransform ); set( mIsOrtho, getFov(), getAspectRatio(), nearDist, farDist, xfm ); }
static void getGenusAndRatio(std::vector<MElement *> &elements, int & genus, int &AR, int &NB) { std::vector<std::vector<MEdge> > boundaries; boundaries.clear(); genus = getGenus(elements, boundaries); NB = boundaries.size(); AR = getAspectRatio(elements, boundaries); }
CameraFrustum * Camera::getCameraFrustum() const { static const glm::vec4 DIR(0.0f, 0.0f, -1.0f, 0.0f); static const glm::vec4 RIGHT(1.0f, 0.0f, 0.0f, 0.0f); static const glm::vec4 UP(0.0f, 1.0f, 0.0f, 0.0f); const glm::vec3 cameraPos(getPosition()); const glm::vec3& dir = glm::vec3(Rinv_ * DIR); const glm::vec3& right = glm::vec3(Rinv_ * RIGHT); const glm::vec3& up = glm::vec3(Rinv_ * UP); const glm::vec2& nearSize = computePlaneSize(FOVY, NEAR_PLANE, getAspectRatio()); const glm::vec3 nc = cameraPos + dir * NEAR_PLANE; const glm::vec3& a = up * nearSize.y; const glm::vec3& b = right * nearSize.x; const glm::vec3 ntl = nc + (a / 2.0f) - (b / 2.0f); const glm::vec3 ntr = ntl + b; const glm::vec3 nbl = ntl - a; const glm::vec3 nbr = nbl + b; const glm::vec2& farSize = computePlaneSize(FOVY, FAR_PLANE, getAspectRatio()); const glm::vec3 fc = cameraPos + dir * FAR_PLANE; const glm::vec3& c = up * farSize.y; const glm::vec3& d = right * farSize.x; const glm::vec3 ftl = fc + (c / 2.0f) - (d / 2.0f); const glm::vec3 ftr = ftl + d; const glm::vec3 fbl = ftl - c; const glm::vec3 fbr = fbl + d; // Order may seem strange, but I use the most distant vectors // to define planes. This way I believe the greatest accuracy // possible is achieved. CameraFrustum *const frustum = new CameraFrustum(); frustum->planes_[0] = Plane(ftr, fbr, ntr); // Right plane frustum->planes_[1] = Plane(fbl, ftl, nbl); // Left plane frustum->planes_[2] = Plane(ftl, ftr, ntl); // Top plane frustum->planes_[3] = Plane(fbr, fbl, nbr); // Bottom plane frustum->planes_[4] = Plane(nbr, nbl, ntr); // Near plane frustum->planes_[5] = Plane(fbr, ftr, fbl); // Far plane return frustum; }
void PostProcessSample::initialize() { _font = Font::create("res/ui/arial.gpb"); // Load game scene from file _scene = Scene::load("res/common/duck.gpb"); _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); // Initialize box model _modelNode = _scene->findNode("duck"); Model* model = dynamic_cast<Model*>(_modelNode->getDrawable()); Material* material = model->setMaterial("res/common/duck.material"); // Get light node Node* lightNode = _scene->findNode("directionalLight1"); Light* light = lightNode->getLight(); material->getParameter("u_directionalLightColor[0]")->setValue(light->getColor()); material->getParameter("u_directionalLightDirection[0]")->setValue(lightNode->getForwardVectorView()); // Create one frame buffer for the full screen compositerss. _frameBuffer = FrameBuffer::create("PostProcessSample", FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT); DepthStencilTarget* dst = DepthStencilTarget::create("PostProcessSample", DepthStencilTarget::DEPTH_STENCIL, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT); _frameBuffer->setDepthStencilTarget(dst); SAFE_RELEASE(dst); // Create our compositors that all output to the default framebuffer. Compositor* compositor = NULL; compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Passthrough"); _compositors.push_back(compositor); compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Grayscale"); _compositors.push_back(compositor); compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Sepia"); _compositors.push_back(compositor); compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Pixelate"); _compositors.push_back(compositor); compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Sobel Edge"); _compositors.push_back(compositor); compositor->getMaterial()->getParameter("u_width")->setValue((float)FRAMEBUFFER_WIDTH / 2.0f); compositor->getMaterial()->getParameter("u_height")->setValue((float)FRAMEBUFFER_HEIGHT / 2.0f); compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Gaussian Blur"); _compositors.push_back(compositor); compositor->getMaterial()->getParameter("u_length")->setValue(1.0f / ((float)FRAMEBUFFER_WIDTH / 2.0f)); compositor = Compositor::create(_frameBuffer, NULL, "res/common/postprocess/postprocess.material", "Old Film"); _compositors.push_back(compositor); compositor->getMaterial()->getParameter("u_sepiaValue")->setValue(0.8f); compositor->getMaterial()->getParameter("u_noiseValue")->setValue(0.4f); compositor->getMaterial()->getParameter("u_scratchValue")->setValue(0.4f); compositor->getMaterial()->getParameter("u_innerVignetting")->setValue(0.9f); compositor->getMaterial()->getParameter("u_outerVignetting")->setValue(0.9f); }
void App::onResize( void ) { D3DApp::onResize(); // Update the aspect ratio and recompute the projection matrix. DirectX::XMMATRIX P = DirectX::XMMatrixPerspectiveFovLH( 0.25f * MathHelper::Pi, getAspectRatio(), 1.f, 1000.f ); XMStoreFloat4x4( &mProj, P ); }
//---------------------------------------------------------------------------// void CameraComponent::recalculateFrustumPlanes() { //If the camera's projection matrix is an orthogonal projection, the frustum planes have to be derived //from the general projection matrix if( m_bIsOrtho ) { glm::mat4 projT = glm::transpose( m_matProjection ); m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_NEAR] = projT[ 3 ] + projT[ 2 ]; m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_FAR] = projT[ 3 ] - projT[ 2 ]; m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_LEFT] = projT[ 3 ] + projT[ 0 ]; m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_RIGHT] = projT[ 3 ] - projT[ 0 ]; m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_BOTTOM] = projT[ 3 ] + projT[ 1 ]; m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_TOP] = projT[ 3 ] - projT[ 1 ]; //The normals in the plane-vectors (N.x, N.y, N.z, D) have to be normalized glm::vec3 v3N; for( uint i = 0; i < 6; ++i ) { v3N = glm::normalize( glm::vec3( m_v4FrustumPlanesVS[ i ] ) ); m_v4FrustumPlanesVS[ i ].x = v3N.x; m_v4FrustumPlanesVS[ i ].y = v3N.y; m_v4FrustumPlanesVS[ i ].z = v3N.z; } } //If the camera's projection matrix is a perpsective projection, the view-space frustum planes can be //determined by the proj-parameters of the camera (more efficient this way) else { float fe1 = glm::sqrt( m_fFocalLength * m_fFocalLength + 1 ); float fea = glm::sqrt( m_fFocalLength * m_fFocalLength + getAspectRatio() * getAspectRatio() ); m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_NEAR ] = glm::vec4( 0.0f, 0.0f, -1.0f, -m_fNear ); m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_FAR ] = glm::vec4( 0.0f, 0.0f, 1.0f, m_fFar ); m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_LEFT ] = glm::vec4( m_fFocalLength / fe1, 0.0f, -1.0f / fe1, 0.0f ); m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_RIGHT ] = glm::vec4( -m_fFocalLength / fe1, 0.0f, -1.0f / fe1, 0.0f ); m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_BOTTOM ] = glm::vec4( 0.0f, m_fFocalLength / fea, -getAspectRatio() / fea, 0.0f ); m_v4FrustumPlanesVS[(uint) EFrustumPlane::PLANE_TOP ] = glm::vec4( 0.0f, -m_fFocalLength / fea, -getAspectRatio() / fea, 0.0f ); } }
void TemplateGame::initialize() { // Load game scene from file _scene = Scene::load("res/demo.scene"); // Get the box model and initialize its material parameter values and bindings Node* boxNode = _scene->findNode("box"); Model* boxModel = dynamic_cast<Model*>(boxNode->getDrawable()); Material* boxMaterial = boxModel->getMaterial(); // Set the aspect ratio for the scene's camera to match the current resolution _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); }
iaVector3f iView::unProject(const iaVector3f& screenpos, const iaMatrixf& modelMatrix) { iaMatrixf viewMatrix; viewMatrix.lookAt(modelMatrix._pos, modelMatrix._pos - modelMatrix._depth, modelMatrix._top); iaMatrixf modelViewMatrix = viewMatrix; modelViewMatrix *= modelMatrix; iaMatrixf projectionMatrix; projectionMatrix.perspective(_viewAngel, getAspectRatio(), _nearPlaneDistance, _farPlaneDistance); return iRenderer::getInstance().unProject(screenpos, modelViewMatrix, projectionMatrix, _resultingRectangle); }
void SceneViewer::initialize() { // Load game scene from file _scene = Scene::load("res/scene.gpb"); _shift_key = false; _control_key = false; _rotate_active = true; _pan_active = false; _zoom_active = false; _touch_x = 0; _touch_y = 0; _grid_on = 1; Camera * cam = _scene->getActiveCamera(); if (cam) { // Set the aspect ratio for the scene's camera to match the current resolution cam->setAspectRatio(getAspectRatio()); cam->getNode()->rotateY(MATH_DEG_TO_RAD(-90)); } // Try to use any significant light source for the scene light vector. // This is just a temporary hack until I manage to tap into the // material file from the python addon. Node * light = _scene->findNode("Spot") ? _scene->findNode("Spot") : _scene->findNode("Area") ? _scene->findNode("Area") : _scene->findNode("Sun") ? _scene->findNode("Sun") : 0; if (light) _directionalLightVector = light->getForwardVector(); // Setup the form and callbacks _form = Form::create("res/editor.form"); _sliderLightVectorX = (Slider *)_form->getControl("lvx"); _sliderLightVectorY = (Slider *)_form->getControl("lvy"); _sliderLightVectorZ = (Slider *)_form->getControl("lvz"); _sliderClearColorRed = (Slider *)_form->getControl("ccRed"); _sliderClearColorGreen = (Slider *)_form->getControl("ccGreen"); _sliderClearColorBlue = (Slider *)_form->getControl("ccBlue"); _bPlayAll = (Button *)_form->getControl("playAll"); _bPlaySelected = (Button *)_form->getControl("playSelected"); _bPlaySelected->setEnabled(false); _gridCheckBox = static_cast<CheckBox*>(_form->getControl("gridCheckBox")); Slider * sliders[] = { _sliderLightVectorX, _sliderLightVectorY, _sliderLightVectorZ, _sliderClearColorRed, _sliderClearColorGreen, _sliderClearColorBlue }, *s; FOREACH(s, sliders) { s->addListener(this, Listener::VALUE_CHANGED); }
bool dskOptions::cmpVideoModes(const VideoMode& left, const VideoMode& right) { if(left == right) return false; VideoMode leftRatio = getAspectRatio(left); VideoMode rightRatio = getAspectRatio(right); // Cmp ratios descending (so 16:9 is above 4:3 as wider ones are more commonly used) if(leftRatio.width > rightRatio.width) return true; else if(leftRatio.width < rightRatio.width) return false; else if(leftRatio.height > rightRatio.height) return true; else if(leftRatio.height < rightRatio.height) return false; // Same ratios -> cmp width/height if(left.width < right.width) return true; else if(left.width > right.width) return false; else return left.height < right.height; }
void SceneLoadSample::initialize() { // Create the font for drawing the framerate. _font = Font::create("res/ui/arial.gpb"); _scene = Scene::load("res/common/sample.scene"); // Update the aspect ratio for our scene's camera to match the current device resolution _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); // Visit all the nodes in the scene, drawing the models/mesh. _scene->visit(this, &SceneLoadSample::initializeMaterials); }
AffineTransform RenderSVGContainer::viewportTransform() const { // FIXME: The method name is confusing, since it does not // do viewport translating anymore. Look into this while // fixing bug 12207. if (!viewBox().isEmpty()) { FloatRect viewportRect = viewport(); if (!parent()->isSVGContainer()) viewportRect = FloatRect(viewport().x(), viewport().y(), width(), height()); return getAspectRatio(viewBox(), viewportRect); } return AffineTransform(); }
//---------------------------------------------------------------------------// void CameraComponent::setProjectionPersp( float yFov_deg, float fWidth, float fHeight, float fNear, float fFar ) { m_matProjection = MathUtil::perspectiveFov( yFov_deg, fWidth, fHeight, fNear, fFar ); m_fNear = fNear; m_fFar = fFar; m_fFovDeg = yFov_deg; m_bIsOrtho = false; m_fWidth = fWidth; m_fHeight = fHeight; //Calculate focal length float fFovHor2 = glm::atan( getAspectRatio() * glm::tan( getFovRad() / 2.0f ) ); m_fFocalLength = 1.0f / glm::tan( fFovHor2 ); onProjectionChanged(); }
void kore::Camera::setProjectionPersp(float yFov_deg, float fWidth, float fHeight, float fNear, float fFar) { _matProjection = glm::perspectiveFov(yFov_deg, fWidth, fHeight, fNear, fFar); _fNear = fNear; _fFar = fFar; _fFovDeg = yFov_deg; _bIsOrtho = false; _fWidth = fWidth; _fHeight = fHeight; // Calculate focal length float fFovHor2 = glm::atan( getAspectRatio() * glm::tan(getFovRad() / 2.0f)); _fFocalLength = 1.0f / glm::tan(fFovHor2); paramsChanged(); }
// Big thanks to http://schabby.de/picking-opengl-ray-tracing/ glm::vec3 Camera::getMouseRay(const int x, const int y) const { // 3D const glm::vec2& half = computePlaneSize(glm::radians(FOVY), NEAR_PLANE, getAspectRatio()) / 2.0f; // 2D const float windowHalfWidth = static_cast<float>(viewportSize_.x) / 2.0f; const float windowHalfHeight = static_cast<float>(viewportSize_.y) / 2.0f; const float xp = x / windowHalfWidth - 1.0f; const float yp = -y / windowHalfHeight + 1.0f; // const glm::vec4 directionInCameraSpace(0.0f, 0.0f, -1.0f, 1.0f); const glm::vec4 directionInCameraSpace(xp * half.x, yp * half.y, -NEAR_PLANE, 0); const glm::vec4 directionInWorldSpace = Rinv_ * directionInCameraSpace; const glm::vec3 v3 = glm::vec3(directionInWorldSpace); // return glm::fastNormalize(v3); return glm::normalize(v3); }
void iView::draw() { iRenderer::getInstance().setViewport(_resultingRectangle.getX(), _resultingRectangle.getY(), _resultingRectangle.getWidth(), _resultingRectangle.getHeight()); iRenderer::getInstance().setClearColor(_clearColor); iRenderer::getInstance().setClearDepth(_clearDepth); if (_clearColorActive) { iRenderer::getInstance().clearColorBuffer(); } if (_clearDepthActive) { iRenderer::getInstance().clearDepthBuffer(); } if (_perspective) { iRenderer::getInstance().setPerspective(_viewAngel, getAspectRatio(), _nearPlaneDistance, _farPlaneDistance); } else { iRenderer::getInstance().setOrtho(_left, _right, _bottom, _top, _nearPlaneDistance, _farPlaneDistance); } iStatistics::getInstance().beginSection(_scenePreparationSectionID); if (_scene != nullptr) { _scene->handle(); } iStatistics::getInstance().endSection(_scenePreparationSectionID); if (_scene != nullptr) { _renderEngine.render(); } iStatistics::getInstance().beginSection(_postRenderSectionID); _renderEvent(); iStatistics::getInstance().endSection(_postRenderSectionID); }
void SpaceshipGame::initialize() { // TODO: Not working on iOS // Display the gameplay splash screen for at least 1 second. displayScreen(this, &SpaceshipGame::drawSplash, NULL, 1000L); // Create our render state block that will be reused across all materials _stateBlock = RenderState::StateBlock::create(); _stateBlock->setDepthTest(true); _stateBlock->setCullFace(true); _stateBlock->setBlend(true); _stateBlock->setBlendSrc(RenderState::BLEND_SRC_ALPHA); _stateBlock->setBlendDst(RenderState::BLEND_ONE_MINUS_SRC_ALPHA); // Load our scene from file _scene = Scene::load("res/spaceship.gpb"); // Update the aspect ratio for our scene's camera to match the current device resolution _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); // Initialize scene data initializeSpaceship(); initializeEnvironment(); // Create a background audio track _backgroundSound = AudioSource::create("res/background.ogg"); if (_backgroundSound) _backgroundSound->setLooped(true); // Create font _font = Font::create("res/airstrip.gpb"); // Store camera node _cameraNode = _scene->findNode("camera1"); // Store initial ship and camera positions _initialShipPos = _shipGroupNode->getTranslation(); _initialShipRot = _shipGroupNode->getRotation(); _initialCameraPos = _cameraNode->getTranslation(); }
ActionRetCodeEnum RotoShapeRenderNode::isIdentity(TimeValue time, const RenderScale & scale, const RectI & roi, ViewIdx view, const ImagePlaneDesc& /*plane*/, TimeValue* inputTime, ViewIdx* inputView, int* inputNb, ImagePlaneDesc* /*inputPlane*/) { *inputView = view; NodePtr node = getNode(); *inputNb = -1; RotoDrawableItemPtr rotoItem = getAttachedRotoItem(); if (!rotoItem) { return eActionStatusFailed; } Bezier* isBezier = dynamic_cast<Bezier*>(rotoItem.get()); if (!rotoItem || !rotoItem->isActivated(time, view) || (isBezier && ((!isBezier->isCurveFinished(view) && !isBezier->isOpenBezier()) || isBezier->getControlPointsCount(view) <= 1))) { *inputTime = time; *inputNb = 0; return eActionStatusOK; } bool isPainting = isDuringPaintStrokeCreation(); RectD maskRod; getRoDFromItem(rotoItem, time, view, isPainting, &maskRod); RectI maskPixelRod; maskRod.toPixelEnclosing(scale, getAspectRatio(-1), &maskPixelRod); if ( !maskPixelRod.intersects(roi) ) { *inputTime = time; *inputNb = 0; } return eActionStatusOK; } // isIdentity
void Geoms::initialize() { setMultiTouch(true); // Load game scene from file _scene = Scene::load("res/box.gpb"); // Set the aspect ratio for the scene's camera to match the current resolution _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); // Get light node Node* lightNode = _scene->findNode("directionalLight"); Light* light = lightNode->getLight(); // Initialize box model Node* boxNode = _scene->findNode("box"); Model* boxModel = boxNode->getModel(); Material* boxMaterial = boxModel->setMaterial("res/box.material"); boxMaterial->getParameter("u_ambientColor")->setValue(_scene->getAmbientColor()); boxMaterial->getParameter("u_lightColor")->setValue(light->getColor()); boxMaterial->getParameter("u_lightDirection")->setValue(lightNode->getForwardVectorView()); }
void TemplateGame::initialize() { // Load game scene from file _scene = Scene::load("res/box.gpb"); // Set the aspect ratio for the scene's camera to match the current resolution _scene->getActiveCamera()->setAspectRatio(getAspectRatio()); // Get light node Node* lightNode = _scene->findNode("directionalLight"); Light* light = lightNode->getLight(); // Initialize box model Node* boxNode = _scene->findNode("box"); Model* boxModel = boxNode->getModel(); Material* boxMaterial = boxModel->setMaterial("res/box.material"); boxMaterial->getParameter("u_ambientColor")->setValue(_scene->getAmbientColor()); boxMaterial->getParameter("u_lightColor")->setValue(light->getColor()); boxMaterial->getParameter("u_lightDirection")->setValue(lightNode->getForwardVectorView()); Platform::displayAdMobAds(true, "ca-app-pub-4039489503962745/7205385230"); }
/* * patchVbios - call the vendor specific function to patch the VESA tables * x & y are horizontal and vertical dimensions respectively, in pixels * for GMA and ATI, only first mode in Table is patched * * each vendor specific function have the same form : * bool vendorSetMode_type(sModeTable * table, uint8_t index, uint32_t * x, uint32_t * y); * where 'table' is the VESA table to patch, 'index' is the index of the mode in table, * 'x' & 'y' are pointer to the target resolution and return the next resolution in table. */ void patchVbios(vBiosMap * map, uint32_t x, uint32_t y, uint32_t bp, uint32_t hTotal, uint32_t vTotal) { uint32_t i = 0; sModeTable * table = map->modeTables; // save the target resolution for future use map->currentX = x; map->currentY = y; unlockVbios(map); // Get the aspect ratio for the requested mode getAspectRatio(&map->aspectRatio, x, y); i = 0; // Call the vendor specific function for each available VESA Table table = map->modeTables; while (table != NULL) { //reset resolution value before treating a new table x = map->currentX; y = map->currentY; PRINT("Patching Table #%d: \n", table->id); map->setMode(table, i, &x, &y); #ifdef AUTORES_DEBUG pause(); #endif table = table->next; } relockVbios(map); return; }
void CubeTest::initialize() { _scene = Scene::load( "res/world.scene" ); if( !_scene ) { printf("Couldn't load scene!"); Game::getInstance()->exit(); } // Set the aspect ratio for the scene's camera to match the current resolution _camera = _scene->getActiveCamera(); _camera->setAspectRatio(getAspectRatio()); Node * sun = _scene->findNode("sun"); Node * box = _scene->findNode("box"); Node * monkey = _scene->findNode("X"); Node * spot = _scene->findNode("spot"); _camera->getNode()->rotateY( MATH_DEG_TO_RAD(270.0f) ); Node * camNode = _camera->getNode(); //camNode->setTranslation(0, 0, 0); //camNode->setRotation(1, 0, 0, 0); //camNode->translate(0, -10, 10); //camNode->rotateX( MATH_DEG_TO_RAD(225.0f) ); //camNode->rotateX( MATH_DEG_TO_RAD(-10.0f)); Vector3 f = camNode->getForwardVector(); bindSpotLight( box->getModel()->getMaterial(0), spot ); bindDirectionalLight( box->getModel()->getMaterial(0), sun ); bindDirectionalLight( monkey->getModel()->getMaterial(0), sun ); //printf("<%.3f, %.3f, %.3f>\n", f.x, f.y, f.z ); //dumpModel( box ); }
void CreateSceneSample::initialize() { // Create the font for drawing the framerate. _font = Font::create("res/ui/arial.gpb"); // Create a new empty scene. _scene = Scene::create(); // Create the camera. Camera* camera = Camera::createPerspective(45.0f, getAspectRatio(), 1.0f, 10.0f); Node* cameraNode = _scene->addNode("camera"); // Attach the camera to a node. This determines the position of the camera. cameraNode->setCamera(camera); // Make this the active camera of the scene. _scene->setActiveCamera(camera); SAFE_RELEASE(camera); // Move the camera to look at the origin. cameraNode->translate(0, 1, 5); cameraNode->rotateX(MATH_DEG_TO_RAD(-11.25f)); // Create a white light. Light* light = Light::createDirectional(0.75f, 0.75f, 0.75f); Node* lightNode = _scene->addNode("light"); lightNode->setLight(light); // Release the light because the node now holds a reference to it. SAFE_RELEASE(light); lightNode->rotateX(MATH_DEG_TO_RAD(-45.0f)); // Create the cube mesh and model. Mesh* cubeMesh = createCubeMesh(); Model* cubeModel = Model::create(cubeMesh); // Release the mesh because the model now holds a reference to it. SAFE_RELEASE(cubeMesh); // Create the material for the cube model and assign it to the first mesh part. Material* material = cubeModel->setMaterial("res/shaders/textured.vert", "res/shaders/textured.frag", "DIRECTIONAL_LIGHT_COUNT 1"); // These parameters are normally set in a .material file but this example sets them programmatically. // Bind the uniform "u_worldViewProjectionMatrix" to use the WORLD_VIEW_PROJECTION_MATRIX from the scene's active camera and the node that the model belongs to. material->setParameterAutoBinding("u_worldViewProjectionMatrix", "WORLD_VIEW_PROJECTION_MATRIX"); material->setParameterAutoBinding("u_inverseTransposeWorldViewMatrix", "INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX"); // Set the ambient color of the material. material->getParameter("u_ambientColor")->setValue(Vector3(0.2f, 0.2f, 0.2f)); // Bind the light's color and direction to the material. material->getParameter("u_directionalLightColor[0]")->setValue(lightNode->getLight()->getColor()); material->getParameter("u_directionalLightDirection[0]")->bindValue(lightNode, &Node::getForwardVectorWorld); // Load the texture from file. Texture::Sampler* sampler = material->getParameter("u_diffuseTexture")->setValue("res/png/crate.png", true); sampler->setFilterMode(Texture::LINEAR_MIPMAP_LINEAR, Texture::LINEAR); material->getStateBlock()->setCullFace(true); material->getStateBlock()->setDepthTest(true); material->getStateBlock()->setDepthWrite(true); _cubeNode = _scene->addNode("cube"); _cubeNode->setModel(cubeModel); _cubeNode->rotateY(MATH_PIOVER4); SAFE_RELEASE(cubeModel); }