void Camera::snapshot(const std::string& filename) { LOG_F_DEBUG("render", "Taking snapshot!"); IImage* img = mIrr.mpVideoDriver->createScreenShot(); if(!img) LOG_F_ERROR("render", "Snapshot mage is null!"); else { if (!mIrr.mpVideoDriver->writeImageToFile(img, filename.c_str())) LOG_F_ERROR("render", "Could not write snapshot image!"); img->drop(); } }
bool LODNode::updateImpl(glm::mat4 transform, std::shared_ptr<Renderer> renderer){ if(!mVisible) return true; transform *= getTRS(); for(auto iter = mChildNodesID.begin(); iter != mChildNodesID.end(); iter++){ if(!iter->second->updateImpl(transform, renderer)){ LOG_F_ERROR(MGF_LOG_FILE, "Rendering Failed!"); return false; } } return true; }
/** * Add a sky box to display a background view. This requires six images: up, down, left, right, front and back. * The images are assumed to be of the form box_base_name + x + extension, where x is "_up.", "_dn.", "_lf.", * "_rt.", "_ft." and "_bk." respectively. * @param box_base_name base name of the images - converted using findResource internally * @param extension image file extesion (such as jpg or png) */ void SimContext::AddSkyBox( const std::string& box_base_name, const std::string& extension ) { ITexture* up = mIrr.getVideoDriver()->getTexture( Kernel::findResource(box_base_name + "_up." + extension).c_str() ); ITexture* dn = mIrr.getVideoDriver()->getTexture( Kernel::findResource(box_base_name + "_dn." + extension).c_str() ); ITexture* lf = mIrr.getVideoDriver()->getTexture( Kernel::findResource(box_base_name + "_lf." + extension).c_str() ); ITexture* rt = mIrr.getVideoDriver()->getTexture( Kernel::findResource(box_base_name + "_rt." + extension).c_str() ); ITexture* ft = mIrr.getVideoDriver()->getTexture( Kernel::findResource(box_base_name + "_ft." + extension).c_str() ); ITexture* bk = mIrr.getVideoDriver()->getTexture( Kernel::findResource(box_base_name + "_bk." + extension).c_str() ); if ( !( up && dn && lf && rt && ft && bk ) ) { LOG_F_ERROR( "graphics", "could not load a sky box texture starting with '" << box_base_name << "' and with extension '" << extension << "'."); } mpSkyBox = mIrr.getSceneManager()->addSkyBoxSceneNode(up, dn, lf, rt, ft, bk); }
bool Camera::attach( SimEntityPtr entity, FPSCameraTemplatePtr camera_template ) { Assert(entity); SceneObjectPtr scene_object = entity->GetSceneObject(); if (scene_object && scene_object->mSceneNode) { mCamera = ICameraSceneNode_IPtr( mIrr.mpSceneManager->addCameraSceneNodeNeroFP(scene_object->mSceneNode.get())); mCamera->setPosition(ConvertNeroToIrrlichtPosition(camera_template->attach_point)); mCamera->setTarget(ConvertNeroToIrrlichtPosition(camera_template->target)); mCamera->setNearValue(camera_template->near_plane); mCamera->setFarValue(camera_template->far_plane); mCamera->bindTargetAndRotation(true); scene_object->attachCamera(shared_from_this()); setFunctionality(Camera::kFunc_FPS); } else { LOG_F_ERROR("render", "Unable to attach to simulation entity: " << entity); return false; } return true; }
/** * Load this object from a template * @param objTemplate template to load from * @return true if success */ bool SceneObject::LoadFromTemplate( ObjectTemplatePtr objTemplate, const SimEntityData& data ) { if( !objTemplate ) return false; Assert( objTemplate->mpSimFactory ); // cast to object template to the type we expect mSceneObjectTemplate = static_pointer_cast< SceneObjectTemplate, ObjectTemplate>( objTemplate ); IrrFactory& irrFactory = mSceneObjectTemplate->mpSimFactory->getIrrFactory(); // are we an animated mesh? if( mSceneObjectTemplate->mAniMesh ) { mAniSceneNode = irrFactory.addAnimatedMeshSceneNode( mSceneObjectTemplate->mAniMesh.get() ); if (mSceneObjectTemplate->mCastsShadow) { mAniSceneNode->addShadowVolumeSceneNode(); } mFPSCamera = mSceneObjectTemplate->mFPSCamera; // reminder to attach camera later mAniSceneNode->setAnimationSpeed(0); mStartFrame = mAniSceneNode->getStartFrame(); mEndFrame = mAniSceneNode->getEndFrame(); mAniSceneNode->setFrameLoop(0,0); mAniSceneNode->setCurrentFrame(0); mSceneNode = mAniSceneNode; } // are we a terrain? else if( mSceneObjectTemplate->mHeightmap != "" ) { mTerrSceneNode = irrFactory.addTerrainSceneNode( mSceneObjectTemplate->mHeightmap.c_str() ); mSceneNode = mTerrSceneNode; mTerrSceneNode->scaleTexture( mSceneObjectTemplate->mScaleTexture.X, mSceneObjectTemplate->mScaleTexture.Y ); } // are we a particle system? else if( mSceneObjectTemplate->mParticleSystem != "" ) { mParticleSystemNode = irrFactory.addParticleSystemNode( mSceneObjectTemplate->mParticleSystem ); mSceneNode = mParticleSystemNode; // don't add a triangle selector for a particle node } if( mSceneNode ) { // assign the textures for( uint32_t i = 0; i < (uint32_t)mSceneObjectTemplate->mTextures.size(); ++i ) mSceneNode->setMaterialTexture( i, mSceneObjectTemplate->mTextures[i].get() ); // set the material flags std::vector<IrrMaterialFlag>::const_iterator flagItr = mSceneObjectTemplate->mMaterialFlags.begin(); std::vector<IrrMaterialFlag>::const_iterator flagEnd = mSceneObjectTemplate->mMaterialFlags.end(); for( ; flagItr != flagEnd; ++flagItr ) mSceneNode->setMaterialFlag( flagItr->mFlag, flagItr->mValue ); // set the material type mSceneNode->setMaterialType( mSceneObjectTemplate->mMaterialType ); // set the node scale Vector3f scale = mSceneObjectTemplate->mScale; /// we can optionally multiply by a custom scale scale.X = scale.X * data.GetScale().X; scale.Y = scale.Y * data.GetScale().Y; scale.Z = scale.Z * data.GetScale().Z; mSceneNode->setScale( ConvertNeroToIrrlichtPosition(scale) ); // make the id of the scene node the same as the SimId of our object mSceneNode->setID(ConvertSimIdToSceneId(data.GetId(), data.GetType())); // set the position of the object SetPosition( data.GetPosition() ); // set the rotation of the object SetRotation( data.GetRotation() ); // set up the triangle selector for this object //if (data.GetType() > 0) { { ITriangleSelector_IPtr tri_selector = GetTriangleSelector(); if (!tri_selector) { LOG_F_WARNING("collision", "could not create triangle selector for collisions with object " << GetId()); } } //} // additionally, add a collision response animator if (canCollide()) { // the world will return the triangles that match the type mask ITriangleSelector* world = new CollideByTypeTriangleSelector(mSceneObjectTemplate->mCollisionMask); // get the axis-aligned bounding box for the node BBoxf box = mSceneNode->getBoundingBox(); // use the aabbox to make the ellipsoid for the collision response animator Vector3f ellipsoid_radius = box.MaxEdge - box.getCenter(); // TODO: might add gravity here Vector3f gravity(0,0,0); // ellipsoid translation relative to object coordinates Vector3f ellipsoid_translation(0,0,0); mCollider = GetSceneManager()->createCollisionResponseAnimator( world, mSceneNode.get(), ellipsoid_radius, gravity, ellipsoid_translation); if (!mCollider) { LOG_F_ERROR("collision", "could not create Collision Response Animator for object id: " << data.GetId()); } else { SafeIrrDrop(world); // we don't need the handle mSceneNode->addAnimator(mCollider.get()); LOG_F_DEBUG("collision", "added collision response animator for object id: " << data.GetId() << " of type: " << data.GetType() << " for collision with mask: " << mSceneObjectTemplate->mCollisionMask << " with bounding ellipsoid: " << ellipsoid_radius); } } #if SCENEOBJECT_ENABLE_STATS // debug information if( mTerrSceneNode ) { const aabbox3df& bbox = mTerrSceneNode->getBoundingBox(); vector3df dim = bbox.MaxEdge - bbox.MinEdge; float32_t vol = dim.X * dim.Y * dim.Z; vol = (vol<0) ? -vol : vol; LOG_F_MSG( "render", "Added terrain with heightmap: " << mSceneObjectTemplate->mHeightmap ); LOG_F_MSG( "render", " Dim: (" << dim.X << ", " << dim.Y << ", " << dim.Z << ")" ); LOG_F_MSG( "render", " Volume: " << vol ); } #endif // end SCENEOBJECT_ENABLE_STATS } return true; }