TEST(TestNodeAAB, TestAABSimple) { MockLoader mock; auto node = std::make_shared<FTShaderNode<MockShader>>(); node->setSize(glm::vec3(34, 88, 22)); node->updateMatrices(); node->updateAAB(node->getTransformMatrix()); EXPECT_EQ(node->getAABCenter(), glm::vec3(17, 44, 11)); EXPECT_EQ(node->getAABHalfExtents(), glm::vec3(17, 44, 11)); node->setPosition(glm::vec3(542, 2, 7)); node->updateMatrices(); node->updateAAB(node->getTransformMatrix()); EXPECT_EQ(node->getAABCenter(), glm::vec3(17 + 542, 44 + 2, 11 + 7.0f)); EXPECT_EQ(node->getAABHalfExtents(), glm::vec3(17, 44, 11)); node->setScale(glm::vec3(5, 2, 7)); node->updateMatrices(); node->updateAAB(node->getTransformMatrix()); EXPECT_EQ(node->getAABCenter(), glm::vec3(17*5 + 542, 44*2 + 2, 11*7 + 7.0f)); EXPECT_EQ(node->getAABHalfExtents(), glm::vec3(17*5, 44*2, 11*7)); auto quat = glm::angleAxis((float)M_PI_2, glm::vec3(0, 0, 1)); node->setRotationQuaternion(quat); node->updateMatrices(); node->updateAAB(node->getTransformMatrix()); EXPECT_EQ(node->getAABCenter(), glm::vec3(542 - 44 * 2, 2+17 * 5, 11 * 7 + 7.0f)); EXPECT_EQ(node->getAABHalfExtents(), glm::vec3(44 * 2, 17 * 5, 11 * 7)); }
TEST(TestNodeAAB, TestAABAnchorPoint) { MockLoader mock; auto node = std::make_shared<FTShaderNode<MockShader>>(); node->setAnchorPoint(glm::vec3(0.3f, 0.5f, 0.7f)); node->setSize(glm::vec3(34, 88, 22)); node->updateMatrices(); node->updateAAB(node->getTransformMatrix()); expectVectorEqual(node->getAABCenter(), glm::vec3(17 - 0.3f * 34, 0, 11 - 0.7f * 22)); expectVectorEqual(node->getAABHalfExtents(), glm::vec3(17, 44, 11)); node->setPosition(glm::vec3(542, 2, 7)); node->updateMatrices(); node->updateAAB(node->getTransformMatrix()); expectVectorEqual(node->getAABCenter(), glm::vec3(17 - 0.3f * 34 + 542, 2, 11 - 0.7f * 22 + 7.0f)); expectVectorEqual(node->getAABHalfExtents(), glm::vec3(17, 44, 11)); node->setScale(glm::vec3(5, 2, 7)); node->updateMatrices(); node->updateAAB(node->getTransformMatrix()); expectVectorEqual(node->getAABCenter(), glm::vec3((17 - 0.3f * 34) * 5 + 542, 2, (11 - 0.7f * 22) * 7 + 7.0f), 0.00001f); expectVectorEqual(node->getAABHalfExtents(), glm::vec3(17 * 5, 44 * 2, 11 * 7)); auto quat = glm::angleAxis((float)M_PI_2, glm::vec3(0, 0, 1)); node->setRotationQuaternion(quat); node->updateMatrices(); node->updateAAB(node->getTransformMatrix()); expectVectorEqual(node->getAABCenter(), glm::vec3(542, 2 + (17 - 0.3f * 34) * 5, (11 - 0.7f * 22) * 7 + 7.0f), 0.00001f); expectVectorEqual(node->getAABHalfExtents(), glm::vec3(44 * 2, 17 * 5, 11 * 7)); }
void Camera::render() { updateMatrices(); device::Device* device = scene.getDevice(); if (device != nullptr) { auto renderTargetSize = device->getRenderTargetSize(); float aspect =static_cast<float>(renderTargetSize.x) / static_cast<float>(renderTargetSize.y); // Rebuild projection when needed if (!math::compareRelative(aspect, this->aspect)) { this->aspect = aspect; projection.buildProjectionMatrixPerspective(fieldOfView, aspect, near, far); std::cout << "Rebuild" << std::endl; } device->setTransform(device::Device::Projection, projection); device->setTransform(device::Device::View, view); } viewFrustum.setMatrix(projection * view); }
RenderObject::RenderObject(string tPath, string sPath, glm::vec2 position, float rotation, glm::vec2 size) { init(); texturePath = tPath; shaderPath = sPath; texture = assetManager->getTexture(texturePath); shader = assetManager->getShader(shaderPath); //UNTIL DYNAMIC LOADING IS FIXED //---------------------------------------------------- if (texture == NULL) { assetManager->forceLoadModel(texturePath); texture = assetManager->getTexture(texturePath); } if (shader == NULL) { assetManager->forceLoadShader(shaderPath); shader = assetManager->getShader(shaderPath); } //---------------------------------------------------- this->position = position; this->rotation = rotation; this->size = size; updateMatrices(); }
void Engine::onMouseMove(int x, int y, uint32_t mouseKeys) { if(m_mouseX < 0) { m_mouseX = x; } if(m_mouseY < 0) { m_mouseX = y; } int dx = m_mouseX - x; int dy = m_mouseY - y; m_mouseX = x; m_mouseY = y; if(mouseKeys & MK_LBUTTON) { m_mainCamera.rotateUp(dx / MOUSE_ROTATE_FACTOR); m_mainCamera.rotateRight(dy / MOUSE_ROTATE_FACTOR); D3DXVECTOR3 look = m_mainCamera.look(); m_mainCamera.setPosition(*D3DXVec3Scale(&look, &look, -m_radius)); updateMatrices(); } }
void SceneView::resizeGL(int w, int h) { if (renderingIsPaused) return; glViewport(0, 0, (GLsizei)w, (GLsizei)h); updateMatrices(); }
bool CMCATask::initialize(const OutputFlag & of, COutputHandler * pOutputHandler, std::ostream * pOstream) { assert(mpProblem && mpMethod); CMCAProblem* pProblem = dynamic_cast<CMCAProblem *>(mpProblem); assert(pProblem); bool success = mpMethod->isValidProblem(mpProblem); //we need to resize an initialize the result matrices before initializing the output success &= updateMatrices(); //initialize reporting success &= CCopasiTask::initialize(of, pOutputHandler, pOstream); CSteadyStateTask *pSubTask = pProblem->getSubTask(); if (pSubTask) success &= pSubTask->initialize(CCopasiTask::NO_OUTPUT, NULL, mReport.getStream()); return success; }
void SceneView::mouseMoveEvent(QMouseEvent *event) { QPoint pos = event->pos(); if (m_button == Qt::LeftButton && event->modifiers() == Qt::NoModifier) { m_alpha += (240.0f * (pos - m_pos).x()) / height(); m_beta += (240.0f * (pos - m_pos).y()) / height(); if (m_beta < -90) m_beta = -90; else if (m_beta > 90) m_beta = 90; } else if (m_button == Qt::RightButton || (m_button == Qt::LeftButton && event->modifiers() == Qt::ControlModifier)) { m_x -= (0.5 * m_z * (pos - m_pos).x()) / height(); m_y += (0.5 * m_z * (pos - m_pos).y()) / height(); } else if (m_button == Qt::MidButton || (m_button == Qt::LeftButton && event->modifiers() == Qt::ShiftModifier)) { m_z -= (m_z * (pos - m_pos).y()) / height(); if (m_z < 0.00001f) m_z = 0.00001f; } m_pos = pos; updateMatrices(); emit updateGL(); }
mat4 SpotLight::getModulationMatrix( double time ) const { updateMatrices(); mat4 modulation = mModulationParams.toMat4( float( time ) ); return modulation * mProjectionMatrix * mViewMatrix; }
bool CSteadyStateTask::initialize(const OutputFlag & of, COutputHandler * pOutputHandler, std::ostream * pOstream) { bool success = true; assert(mpProblem && mpMethod); CSteadyStateProblem* pProblem = dynamic_cast<CSteadyStateProblem *>(mpProblem); assert(pProblem); success &= pProblem->initialize(); CSteadyStateMethod* pMethod = dynamic_cast<CSteadyStateMethod *>(mpMethod); assert(pMethod); success &= pMethod->initialize(pProblem); success &= pMethod->isValidProblem(mpProblem); success &= updateMatrices(); mSteadyState = mpContainer->getState(true); success &= CCopasiTask::initialize(of, pOutputHandler, pOstream); return success; }
void State::updateAll(void) { updateMatrices(); updateMaterial(); updateLight(); updateTexture(); updateFog(); }
void Engine::resize(int width, int height) { if((width <= 0) || (height <= 0)) { return; } matrixPerspectiveFov(&m_projectionMatrix, VIEW_ANGLE, float(width)/float(height), NEAR_PLANE, FAR_PLANE); updateMatrices(); }
void SkinnedMesh::updateMatrices(const D3DXFRAME *frameBase, const D3DXMATRIX *parentMatrix) { FrameEx *currentFrame = (FrameEx*)frameBase; // If parent matrix exists multiply our frame matrix by it if (parentMatrix != NULL) D3DXMatrixMultiply(¤tFrame->combinedTransform, ¤tFrame->TransformationMatrix, parentMatrix); else currentFrame->combinedTransform = currentFrame->TransformationMatrix; // If we have a sibling recurse if (currentFrame->pFrameSibling != NULL) updateMatrices(currentFrame->pFrameSibling, parentMatrix); // If we have a child recurse if (currentFrame->pFrameFirstChild != NULL) updateMatrices(currentFrame->pFrameFirstChild, ¤tFrame->combinedTransform); }
/** * Constructor with given external ros texture */ srs_ui_but::CProjectionData::CProjectionData( Ogre::SceneManager * manager, const ros::NodeHandle &nh, const std::string & materialName, const std::string & groupName ) : m_texW( 512 ) , m_texH( 512 ) , m_mode( TM_ROS ) , m_manager( manager ) { // std::cerr << "CProjectionData constructor" << std::endl; // Create frustum and projector node m_frustum = new Ogre::Frustum(); m_frustum->setNearClipDistance( 0.8 ); m_projectorNode = manager->getRootSceneNode()->createChildSceneNode("DecalProjectorNode"); m_projectorNode->attachObject(m_frustum); m_projectorNode->setPosition(0,5,0); // Create ros textures m_textureRosRGB = new tRosTextureRGB( nh, "rgb_texture", "rgb8" ); assert( m_textureRosRGB != 0 ); m_textureRosDepth = new tRosTextureDepth( nh, "depth_texture", DEFAULT_DEPTH_IMAGE_TOPIC_NAME, "32FC4" ); assert( m_textureRosDepth != 0 ); // Create and init material m_materialPtr = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().getByName(materialName, groupName); m_materialPtr->load(); // std::cerr << "Num of techniques: " << m_materialPtr->getNumTechniques() << std::endl; m_materialPtr->getTechnique(0)->setLightingEnabled(false); Ogre::Pass *pass = m_materialPtr->getTechnique(0)->getPass(0); pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); pass->setDepthBias(1); pass->setLightingEnabled(false); // Connect rgb texture and material m_texState = pass->createTextureUnitState(m_textureRosRGB->getTexture()->getName()); m_texState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); m_texState->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR, Ogre::FO_NONE); Ogre::LayerBlendOperationEx op = Ogre::LBX_MODULATE; m_texState->setColourOperationEx(op, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE); // Connect Depth texture and material m_texState = pass->createTextureUnitState(m_textureRosDepth->getTexture()->getName()); m_texState->setDesiredFormat( Ogre::PF_FLOAT32_RGB ); m_texState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); m_texState->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR, Ogre::FO_NONE); m_texState->setColourOperationEx(op, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE); updateMatrices(); // std::cerr << "CProjectionData constructor done" << std::endl; }
void Model::Draw() { m_shader.Use(); for(GLuint i = 0; i < this->meshes.size(); i++) this->meshes[i]->Draw(m_shader, m_material[this->meshes[i]->getMaterialIndex()]); if(m_camera.needUpdate()) updateMatrices(); }
void reLight::updateShader( reShader* shader ) { if (updateNeeded) { updateMatrices(); } reMat4 mat(projection*view); //shader->setUniformMatrix("light[0]", 1, glm::value_ptr(mat)); }
void SceneView::resetTransform() { m_alpha = 0.0f; m_beta = 0.0f; m_x = 0.0f; m_y = 0.0f; m_z = 5.0f; updateMatrices(); }
void PerspectiveCamera::initialize(float a_viewportWidth, float a_viewportHeight, float a_horizontalFov, float a_near, float a_far, EProjection a_projection) { m_projection = a_projection; m_near = a_near; m_far = a_far; m_viewportWidth = a_viewportWidth; m_viewportHeight = a_viewportHeight; setHorizontalFieldOfView(a_horizontalFov); updateMatrices(); }
void SceneView::setBackgroundColor(QColor color) { sceneBackgroundColor = color; makeCurrent(); glClearColor(sceneBackgroundColor); doneCurrent(); updateMatrices(); emit updateGL(); }
void Engine::onMouseWheel(int delta) { m_radius -= delta / MOUSE_WHEEL_FACTOR; if(m_radius < 0.0f) { m_radius = 0.0f; } D3DXVECTOR3 look = m_mainCamera.look(); m_mainCamera.setPosition(*D3DXVec3Scale(&look, &look, -m_radius)); updateMatrices(); }
//! render void CCameraSceneNode::render() { updateMatrices(); video::IVideoDriver* driver = SceneManager->getVideoDriver(); if ( driver) { driver->setTransform(video::ETS_PROJECTION, ViewArea.getTransform ( video::ETS_PROJECTION) ); driver->setTransform(video::ETS_VIEW, ViewArea.getTransform ( video::ETS_VIEW) ); } }
void Object::draw(void){ updateMatrices(); glUniformMatrix4fv(glGetUniformLocation(program, "scaleTrans"), 1, GL_TRUE, scaleTrans.ptr<GLfloat>()); glUniformMatrix4fv(glGetUniformLocation(program, "objectRot"), 1, GL_TRUE, totalRot.ptr<GLfloat>()); glUniform3fv(glGetUniformLocation(program, "color"), 1, cv::Mat(color).ptr<GLfloat>()); if(tex != NULL){ glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex->refId); } m->draw(program); }
CellGrid::CellGrid(bool allow_diagonals): FifeClass(), m_matrix(), m_inverse_matrix(), m_xshift(0), m_yshift(0), m_xscale(1), m_yscale(1), m_rotation(0), m_allow_diagonals(allow_diagonals) { updateMatrices(); }
void Renderer::updateMatrices(QSGNode *node, QSGTransformNode *xform) { if (node->isSubtreeBlocked()) return; if (node->type() == QSGNode::TransformNodeType) { QSGTransformNode *tn = static_cast<QSGTransformNode *>(node); if (xform) tn->setCombinedMatrix(xform->combinedMatrix() * tn->matrix()); else tn->setCombinedMatrix(tn->matrix()); QSGNODE_TRAVERSE(node) updateMatrices(child, tn); } else { if (node->type() == QSGNode::GeometryNodeType || node->type() == QSGNode::ClipNodeType) { static_cast<BasicGeometryNode_Accessor *>(node)->m_matrix = xform ? &xform->combinedMatrix() : 0; } QSGNODE_TRAVERSE(node) updateMatrices(child, xform); } }
void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(viewport.x(), viewport.y(), viewport.width(), viewport.height()); updateMatrices(); drawAxes(); drawCube(); drawPoints(); }
void prepare() { VulkanExampleBase::prepare(); // Create a fence for synchronization VkFenceCreateInfo fenceCreateInfo = vkTools::initializers::fenceCreateInfo(VK_FLAGS_NONE); vkCreateFence(device, &fenceCreateInfo, NULL, &renderFence); loadMeshes(); setupVertexDescriptions(); setupPipelineLayout(); preparePipelines(); prepareMultiThreadedRenderer(); updateMatrices(); prepared = true; }
bool CSensTask::initialize(const OutputFlag & of, COutputHandler * pOutputHandler, std::ostream * pOstream) { bool success = true; //this needs to be done before the initialization of the output if (!updateMatrices()) success = false; if (!CCopasiTask::initialize(of, pOutputHandler, pOstream)) success = false; return success; }
ImageMappingInformation::ImageMappingInformation(const cgt::vec3& size, const cgt::vec3& offset, const cgt::vec3& voxelSize, const cgt::mat4& customTransformation /*= LinearMapping<float>::identity*/) : _size(size) , _offset(offset) , _voxelSize(voxelSize) , _customTransformation(customTransformation) { cgt::mat4 invTrafo; if (! _customTransformation.invert(invTrafo)) { LERRORC("CAMPVis.core.ImageMappingInformation", "Custom transformation is not invertable! Resetting to identity tranformation."); _customTransformation = cgt::mat4::identity; } updateMatrices(); }
void MouseView3D::mouseMove(float x, float y) { float pos[] = {x, y}; if (m_mouseLeft) { // update deltaAngle m_angles[0] = m_startAngles[0] - 0.01f * (pos[0] - m_currentPos[0]); m_angles[1] = m_startAngles[1] + 0.01f * (pos[1] - m_currentPos[1]); // Limit the vertical angle (5 to 85 degrees) if (m_angles[1] > DEG2RAD(85)) m_angles[1] = DEG2RAD(85); if (m_angles[0] < DEG2RAD(5)) m_angles[0] = DEG2RAD(5); updateEye(); updateMatrices(); } else if (m_mouseRight) { //Translation float t[3]; t[0] = 0.1f * (pos[0] - m_currentPos[0]); t[1] = 0; t[2] = 0.1f * (pos[1] - m_currentPos[1]); float mt[3]; Mat4_Rtxp(mt, m_modelView, t); m_center[0] = m_startCenter[0] + mt[0]; m_center[1] = m_startCenter[1] + mt[1]; m_center[2] = m_startCenter[2] + mt[2]; updateEye(); updateMatrices(); } }
void NvInputHandler_CameraFly::update(float deltaTime) { // Calculate the deltas for each access to create our new relative transform float yaw = (m_yRotDelta_Mouse * m_rotSpeed_Mouse) + ((m_yPlusRotVel_KB - m_yNegRotVel_KB) * m_rotSpeed_KB * deltaTime) + (m_yRotVel_GP * m_rotSpeed_GP * deltaTime); float pitch = (m_xRotDelta_Mouse * m_rotSpeed_Mouse) + ((m_xPlusRotVel_KB - m_xNegRotVel_KB) * m_rotSpeed_KB * deltaTime) + (m_xRotVel_GP * m_rotSpeed_GP * deltaTime); float kbAccelerate = m_accelerate_KB? 5.0f : 1.0f; float gpAccelerate = m_accelerate_GP? 5.0f : 1.0f; float xDelta = (m_xTransDelta_Mouse * m_transSpeed_Mouse) + ((m_xPlusTransVel_KB - m_xNegTransVel_KB) * m_transSpeed_KB * kbAccelerate * deltaTime) + (m_xTransVel_GP * m_transSpeed_GP * gpAccelerate * deltaTime); float yDelta = (m_yTransDelta_Mouse * m_transSpeed_Mouse) + ((m_yPlusTransVel_KB - m_yNegTransVel_KB) * m_transSpeed_KB * kbAccelerate * deltaTime) + (m_yTransVel_GP * m_transSpeed_GP * gpAccelerate * deltaTime); float zDelta = (m_zTransDelta_Mouse * m_transSpeed_Mouse) + ((m_zPlusTransVel_KB - m_zNegTransVel_KB) * m_transSpeed_KB * kbAccelerate * deltaTime) + (m_zTransVel_GP * m_transSpeed_GP * gpAccelerate * deltaTime); // Translation provided by input is relative to the camera. // Convert to world space translation before adding it. nv::matrix4f currentRotation = m_currentCameraMat; currentRotation.set_translate(nv::vec3f(0.0f, 0.0f, 0.0f)); nv::vec4f worldTranslation = currentRotation * nv::vec4f(xDelta, yDelta, zDelta, 1.0f); m_currentPos.x += worldTranslation.x; m_currentPos.y += worldTranslation.y; m_currentPos.z += worldTranslation.z; // Update our current yaw and pitch, clamping as needed m_currentYaw += yaw; float twopi = (NV_PI * 2.0f); while (m_currentYaw > twopi) { m_currentYaw -= twopi; } m_currentPitch += pitch; if (m_currentPitch > NV_PI) { m_currentPitch = NV_PI; } else if (m_currentPitch < -NV_PI) { m_currentPitch = -NV_PI; } // Clear out the accumulated mouse values m_xRotDelta_Mouse = m_yRotDelta_Mouse = m_zRotDelta_Mouse = 0.0f; m_xTransDelta_Mouse = m_yTransDelta_Mouse = m_zTransDelta_Mouse = 0.0f; updateMatrices(); }