void OgreNewtonDebugger::ShowDebugInformation() { m_lru ++; for (dNewtonBody* body = m_world->GetFirstBody(); body; body = m_world->GetNextBody(body)) { BodyDebugDataMap::iterator item (m_cachemap.find(body)); if (item == m_cachemap.end()) { std::pair<BodyDebugDataMap::iterator, bool> pair (m_cachemap.insert(std::make_pair (body, BodyDebugData()))); item = pair.first; BodyDebugData& data = item->second; data.Init(this, body); } BodyDebugData& data = item->second; if (data.m_lru < (m_lru - 1)) { data.Cleanup(this); m_cachemap.erase (item); } else { data.m_lru = m_lru; Matrix4 matrix; body->GetMatrix (matrix[0]); matrix = matrix.transpose(); data.m_node->setPosition (matrix.getTrans()); data.m_node->setOrientation (matrix.extractQuaternion()); } } }
void CWeaponController::setTransformBone(const Matrix4 &transform) { _weaponTransform = transform; Vector3 pos = _weaponTransform.getTrans(); Quaternion q = _weaponTransform.extractQuaternion(); Matrix4 playerTransform = CServer::getSingletonPtr()->getPlayer()->getTransform(); //Vector3 playerScale = Vector3::ZERO; //playerTransform.getScale(playerScale); Quaternion playerOrientation = playerTransform.extractQuaternion(); q = playerOrientation * q ; q.normalise(); Vector3 newDir = q * _dirFromOrigin; _pivot = pos + newDir; Matrix3 ori; q.ToRotationMatrix(ori); _pivotTransform = ori; _pivotTransform.setTrans(_pivot); //_pivotTransform.setScale(playerScale); //if(!_componenteFisico)//si no tenemos componente físico de arma, seteamos nostros la transformada de la entidad //{ // _entity->setTransform(_pivotTransform); //} _entity->setTransform(_pivotTransform); //en caso contrario preparamos a la física para que lo haga ella ///Al final de todo el proceso, seteo el nodo de escena asociado al pivote en su sitio _node->setPosition(_pivot); }
static void MakeStaticRamp(SceneManager* const sceneMgr, OgreNewtonWorld* const world, const Vector3& location, int rampMaterialID) { Vector3 blockBoxSize (20.0f, 0.25f, 40.0f); dNewtonCollisionBox shape (world, blockBoxSize.x, blockBoxSize.y, blockBoxSize.z, m_all); // create a texture for using with this material Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().load("sand1b.jpg", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); // make a material to use with this mesh MaterialPtr renderMaterial = MaterialManager::getSingleton().create("ramp", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); renderMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(true); renderMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("sand1b.jpg"); renderMaterial->setAmbient(0.2f, 0.2f, 0.2f); OgreNewtonMesh boxMesh (&shape); boxMesh.Triangulate(); int materialId = boxMesh.AddMaterial(renderMaterial); boxMesh.ApplyBoxMapping (materialId, materialId, materialId); // create a manual object for rendering ManualObject* const object = boxMesh.CreateEntity(MakeName ("ramp")); MeshPtr mesh (object->convertToMesh (MakeName ("ramp"))); //Matrix4 matrix (Matrix4::IDENTITY); Matrix4 matrix (Quaternion (Degree(-30.0f), Vector3 (0.0f, 0.0f, 1.0f))); matrix.setTrans (Vector3 (location.x, location.y, location.z)); Entity* const ent = sceneMgr->createEntity(MakeName ("ramp"), mesh); SceneNode* const node = CreateNode (sceneMgr, ent, matrix.getTrans(), matrix.extractQuaternion()); shape.SetMaterialId (rampMaterialID); new OgreNewtonDynamicBody (world, 0.0f, &shape, node, matrix); delete object; }
void TrackingSystem::convertPoseToOgreCoordinate() { const ARToolKitPlus::ARMultiMarkerInfoT* config = mTracker->getMultiMarkerConfig(); Matrix4 invTrans = convert(config->trans).inverseAffine(); Vector3 invTransPosition = invTrans.getTrans(); Quaternion invTransOrientation = invTrans.extractQuaternion(); invTransOrientation = invTransOrientation * mRot180Z; mTranslation = invTransPosition; mOrientation = invTransOrientation; }
// called synchronous from ogre update loop after of updating updating all sceneNodes controlled by a physic body void DemoApplication::OnRenderUpdateEnd(dFloat updateParam) { // set the camera interpolated matrix Matrix4 matrix; Vector3 cameraPosit; Quaternion cameraRotation; // interpolate the camera matrix at rendering time m_cameraSmoothing.InterpolateMatrix (updateParam, &matrix[0][0]); matrix = matrix.transpose(); mCamera->setPosition (matrix.getTrans()); mCamera->setOrientation (matrix.extractQuaternion()); // show statistic and help options m_onScreeHelp.Update (m_keyboard->isKeyDown(OIS::KC_F1) ? true : false); if (m_onScreeHelp.m_state) { int row = 0; const RenderTarget::FrameStats& stats = mWindow->getStatistics(); row = m_screen->write(20, row + 20, "FPS: %05.3f", stats.lastFPS); row = m_screen->write(20, row + 20, "Physics time: %05.3f ms", float (double (m_physicsWorld->GetPhysicsTimeInMicroSeconds()) * 1.0e-3f)); row = m_screen->write(20, row + 20, "Number of rigid bodies: %d", m_physicsWorld->GetBodyCount()); row = m_screen->write(20, row + 20, "F1: Hide debug help text"); row = m_screen->write(20, row + 20, "F2: Toggle %s simulation update", m_physicsWorld->GetConcurrentUpdateMode() ? "Asynchronous" : "Synchronous"); row = m_screen->write(20, row + 20, "F3: Toggle display physic debug"); row = m_screen->write(20, row + 30, "W, S, A, D: Free camera navigation"); row = m_screen->write(20, row + 20, "Hold CTRL and Left Mouse Key: Show mouse cursor and pick objects from the screen"); row = m_screen->write(20, row + 20, "ESC: Exit application"); } else { m_screen->removeAll(); } m_screen->update(); // see if debug display was activated m_debugTriggerKey.Update (m_keyboard->isKeyDown(OIS::KC_F3) ? true : false); if (m_debugTriggerKey.TriggerUp()) { GetPhysics()->WaitForUpdateToFinish(); } m_debugRender->SetDebugMode (m_debugTriggerKey.m_state); // check if the player want to run the physics concurrent of not m_asyncronousUpdateKey.Update (m_keyboard->isKeyDown(OIS::KC_F2) ? true : false); if (m_asyncronousUpdateKey.TriggerUp()) { GetPhysics()->WaitForUpdateToFinish(); m_physicsWorld->SetConcurrentUpdateMode(!m_physicsWorld->GetConcurrentUpdateMode()); } }
static void AddFrictionSamples(SceneManager* const sceneMgr, OgreNewtonWorld* const world, const Vector3& location, int materialStartID) { Vector3 blockBoxSize (0.75f, 0.25f, 0.5f); dNewtonCollisionBox shape (world, blockBoxSize.x, blockBoxSize.y, blockBoxSize.z, m_all); // create a texture for using with this material Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().load("smilli.tga", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); // make a material to use with this mesh MaterialPtr renderMaterial = MaterialManager::getSingleton().create("smalli", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); renderMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(true); renderMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("smilli.tga"); renderMaterial->setAmbient(0.2f, 0.2f, 0.2f); OgreNewtonMesh boxMesh (&shape); boxMesh.Triangulate(); int materialId = boxMesh.AddMaterial(renderMaterial); boxMesh.ApplyBoxMapping (materialId, materialId, materialId); // create a manual object for rendering ManualObject* const object = boxMesh.CreateEntity(MakeName ("ramp")); MeshPtr mesh (object->convertToMesh (MakeName ("ramp"))); //Matrix4 matrix (Matrix4::IDENTITY); Matrix4 matrix (Quaternion (Degree(-30.0f), Vector3 (0.0f, 0.0f, 1.0f))); Vector3 origin (location.x - 8.0f, location.y + 5.125f, location.z + 15.0f); dFloat mass = 10.0f; for (int i = 0; i < 10; i ++) { matrix.setTrans (origin); origin.z -= 3.0f; Entity* const ent = sceneMgr->createEntity(MakeName ("ramp"), mesh); SceneNode* const node = CreateNode (sceneMgr, ent, matrix.getTrans(), matrix.extractQuaternion()); shape.SetMaterialId(materialStartID + i); OgreNewtonDynamicBody* const body = new OgreNewtonDynamicBody (world, mass, &shape, node, matrix); // set the linear and angular drag do zero body->SetLinearDrag (0.0f); body->SetAngularDrag(Vector3 (0.0f, 0.0f, 0.0f)); } delete object; }
void OgreNewtonDebugger::BodyDebugData::Init(OgreNewtonDebugger* const debugger, dNewtonBody* const body) { m_lru = debugger->m_lru; // Vector3 pos, vel, omega; // Quaternion ori; // bod->getVisualPositionOrientation(pos, ori); // vel = bod->getVelocity(); // omega = bod->getOmega(); // ----------- create debug-text ------------ // std::ostringstream oss_name; // oss_name << "__OgreNewt__Debugger__Body__" << bod << "__"; // std::ostringstream oss_info; // oss_info.precision(2); // oss_info.setf(std::ios::fixed,std::ios::floatfield); // Vector3 inertia; // Real mass; // bod->getMassMatrix(mass, inertia); // oss_info << "[" << bod->getOgreNode()->getName() << "]" << std::endl; // oss_info << "Mass: " << mass << std::endl; // oss_info << "Position: " << pos[0] << " x " << pos[1] << " x " << pos[2] << std::endl; // oss_info << "Velocity: " << vel[0] << " x " << vel[1] << " x " << vel[2] << std::endl; // oss_info << "Omega: " << omega[0] << " x " << omega[1] << " x " << omega[2] << std::endl; // oss_info << "Inertia: " << inertia[0] << " x " << inertia[1] << " x " << inertia[2] << std::endl; // ----------- ------------------ ------------ // look for cached data // BodyDebugData* data = &m_cachemap[bod]; /* if( data->m_lastcol == bod->getCollision() ) // use cached data { // set new position... data->m_node->setPosition(pos); data->m_node->setOrientation(ori); data->m_updated = 1; m_debugnode->addChild(data->m_node); data->m_text->setCaption(oss_info.str()); data->m_text->setLocalTranslation(bod->getAABB().getSize().y * 1.1f * Vector3::UNIT_Y); } else { data->m_lastcol = bod->getCollision(); data->m_updated = 1; if( data->m_node ) { data->m_node->detachAllObjects(); data->m_node->setPosition(pos); data->m_node->setOrientation(ori); } else data->m_node = m_debugnode->createChildSceneNode(pos, ori); if( data->m_lines ) { data->m_lines->clear(); } else { std::ostringstream oss; oss << "__OgreNewt__Debugger__Lines__" << bod << "__"; data->m_lines = new ManualObject(oss.str()); } if( data->m_text ) { data->m_text->setCaption(oss_info.str()); data->m_text->setLocalTranslation(bod->getAABB().getMaximum().y * 1.1f * Vector3::UNIT_Y); } else { data->m_text = new OgreNewt::OgreAddons::MovableText( oss_name.str(), oss_info.str(), "BlueHighway-10",0.5); data->m_text->setLocalTranslation(bod->getAABB().getMaximum().y / 2.0f * Vector3::UNIT_Y + Vector3::UNIT_Y * 0.1f); data->m_text->setTextAlignment( OgreNewt::OgreAddons::MovableText::H_LEFT, OgreNewt::OgreAddons::MovableText::V_ABOVE ); } data->m_node->attachObject(data->m_text); // data->m_lines->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST ); // set color // if( it != m_materialcolors.end() ) // data->m_lines->colour(it->second); // else // data->m_lines->colour(m_defaultcolor); // // float matrix[16]; // Converters::QuatPosToMatrix(Quaternion::IDENTITY, Vector3::ZERO, &matrix[0]); // // NewtonCollisionForEachPolygonDo( NewtonBodyGetCollision(newtonBody), &matrix[0], newtonPerPoly, data->m_lines ); // data->m_lines->end(); buildDebugObjectFromCollision (data->m_lines, m_defaultcolor, *bod->getCollision()); data->m_node->attachObject(data->m_lines); } */ Matrix4 matrix; body->GetMatrix (matrix[0]); matrix.transpose(); m_node = debugger->m_debugNode->createChildSceneNode (matrix.getTrans(), matrix.extractQuaternion()); char name[256]; sprintf (name, "__debug_collsion_shape_%d__", debugger->m_uniqueID); debugger->m_uniqueID ++; m_lines = new ManualObject(name); dNewtonCollision* const collision = body->GetCollision(); OgreNewtonGetCollisionMesh getMeshFaces (collision, this); m_lines->begin("BaseWhiteNoLighting", RenderOperation::OT_LINE_LIST ); Matrix4 localMatrix (Matrix4::IDENTITY); collision->DebugRender (localMatrix[0], &getMeshFaces); m_lines->end(); m_node->attachObject(m_lines); }
MmParticle ParticleSystemEmitterPlane::newParticle(int rangeIndex,AnimationTime *pTime) { MmParticle p; // TODO: maybe evaluate these outside the spawn function, since they will be common for a given frame? float w = m_pParticleSystem->m_pData->areal.getFrame(rangeIndex,pTime) * 0.5f; float l = m_pParticleSystem->m_pData->areaw.getFrame(rangeIndex,pTime) * 0.5f; float spd = m_pParticleSystem->m_pData->speed.getFrame(rangeIndex,pTime); float var = m_pParticleSystem->m_pData->variation.getFrame(rangeIndex,pTime); Bone *pBone = m_pParticleSystem->m_pBone; //绑定到骨骼 if( pBone && m_pParticleSystem->m_pData->attach2Bone != 0 ) { //位置 p.m_vPos = m_pParticleSystem->m_pData->pos + Vector3(Math::RangeRandom(-l,l),0,Math::RangeRandom(-w,w)); p.m_vPos = p.m_vPos + pBone->getPivot(); //向下方向 p.m_vDown = Vector3(0,-1,0); //速度 p.m_vSpeed = xs::Vector3::UNIT_Y * spd * (1.0f + Math::RangeRandom(-var,var)); } else//世界绝对位置 { //位置 p.m_vPos = m_pParticleSystem->m_pData->pos + Vector3(Math::RangeRandom(-l,l),0,Math::RangeRandom(-w,w)); if(pBone) p.m_vPos = pBone->getFullTransform() *( pBone->getPivot() + p.m_vPos); if(m_pParticleSystem->m_pNode) { const Matrix4& mtx = m_pParticleSystem->m_pNode->getFullTransform(); p.m_vPos = mtx * p.m_vPos; } //向上方向 Vector3 dir = Vector3(0,1,0); if(pBone) { dir = pBone->getFullRotation() * dir; } if(m_pParticleSystem->m_pNode) { Matrix4 mtx = m_pParticleSystem->m_pNode->getFullTransform(); Quaternion q = mtx.extractQuaternion(); dir = q * dir; } dir.normalize(); //向下方向 p.m_vDown = -1 * dir; p.m_vSpeed = dir * spd * (1.0f + Math::RangeRandom(-var,var)); } p.m_fLife = 0; p.m_fMaxLife = m_pParticleSystem->m_pData->lifespan.getFrame(rangeIndex,pTime); p.m_vOrigin = p.m_vPos; // 随机选择分割的纹理 [5/18/2011 zgz] if (0 == m_pParticleSystem->m_pData->iteratorArea[0] && 0 == m_pParticleSystem->m_pData->iteratorArea[1]) { p.m_i32Tile = Math::RangeRandom(0,m_pParticleSystem->m_pData->rows * m_pParticleSystem->m_pData->cols - 1); } return p; }
void LThing::setUpBodyInfo(PonykartParsers::ThingDefinition* def) { // set up our collision shapes btCollisionShape* shape = LKernel::getG<CollisionShapeManager>()->createAndRegisterShape(this, def); // get the physics type and set up the mass of the body ThingEnum physicsType = def->getEnumProperty("physics"); float mass = physicsType & ThingEnum::Static ? 0 : def->getFloatProperty("mass", 1); // create our construction info thingy btVector3 inertia; shape->calculateLocalInertia(mass, inertia); // if it's static and doesn't have a sound, we don't need a mogre motion state because we'll be disposing of the root node afterwards if (def->getBoolProperty("Static", false) && !soundComponents.size()) motionState = new btDefaultMotionState; else motionState = getInitializationMotionState(); info = new btRigidBody::btRigidBodyConstructionInfo(mass, motionState, shape, inertia); // physics material stuff from a .physmat file string physmat = def->getStringProperty("PhysicsMaterial", "Default"); LKernel::getG<PhysicsMaterialFactory>()->applyMaterial(info, physmat); // we can override some of them in the .thing file auto ftoks = def->getFloatTokens(); if (ftoks.find("bounciness") != ftoks.end()) info->m_restitution = def->getFloatProperty("bounciness", PhysicsMaterial::DEFAULT_BOUNCINESS); if (ftoks.find("friction") != ftoks.end()) info->m_friction = def->getFloatProperty("friction", PhysicsMaterial::DEFAULT_FRICTION); if (ftoks.find("angulardamping") != ftoks.end()) info->m_angularDamping = def->getFloatProperty("angulardamping", PhysicsMaterial::DEFAULT_ANGULAR_DAMPING); if (ftoks.find("lineardamping") != ftoks.end()) info->m_linearDamping = def->getFloatProperty("lineardamping", PhysicsMaterial::DEFAULT_LINEAR_DAMPING); // choose which group to use for a default ThingEnum defaultGroup; if (physicsType & ThingEnum::Dynamic) defaultGroup = ThingEnum::Default; else if (physicsType & ThingEnum::Static) defaultGroup = ThingEnum::Environment; else // kinematic defaultGroup = ThingEnum::Default; // collision group ThingEnum teCollisionGroup = def->getEnumProperty("CollisionGroup", defaultGroup); int pcg=0; if (teCollisionGroup&ThingEnum::All) {pcg=(int)PonykartCollisionGroups::All; goto enumPCGConversionDone;} if (teCollisionGroup&ThingEnum::Default) pcg|=(int)PonykartCollisionGroups::Default; if (teCollisionGroup&ThingEnum::Environment) pcg|=(int)PonykartCollisionGroups::Environment; if (teCollisionGroup&ThingEnum::Affectors) pcg|=(int)PonykartCollisionGroups::Affectors; if (teCollisionGroup&ThingEnum::Road) pcg|=(int)PonykartCollisionGroups::Road; if (teCollisionGroup&ThingEnum::Triggers) pcg|=(int)PonykartCollisionGroups::Triggers; if (teCollisionGroup&ThingEnum::Karts) pcg|=(int)PonykartCollisionGroups::Karts; if (teCollisionGroup&ThingEnum::InvisibleWalls) pcg|=(int)PonykartCollisionGroups::InvisibleWalls; enumPCGConversionDone: if (pcg!=(int)teCollisionGroup) throw string("Invalid collision group!"); collisionGroup = (PonykartCollisionGroups)pcg; // collides-with group ThingEnum teCollidesWith = def->getEnumProperty("CollidesWith", defaultGroup); int pcwg=0; if (teCollidesWith&ThingEnum::All) {pcwg=(int)PonykartCollidesWithGroups::All; goto enumPCWGConversionDone;} if (teCollidesWith&ThingEnum::Default) pcwg|=(int)PonykartCollidesWithGroups::Default; if (teCollidesWith&ThingEnum::Environment) pcwg|=(int)PonykartCollidesWithGroups::Environment; if (teCollidesWith&ThingEnum::Affectors) pcwg|=(int)PonykartCollidesWithGroups::Affectors; if (teCollidesWith&ThingEnum::Road) pcwg|=(int)PonykartCollidesWithGroups::Road; if (teCollidesWith&ThingEnum::Triggers) pcwg|=(int)PonykartCollidesWithGroups::Triggers; if (teCollidesWith&ThingEnum::Karts) pcwg|=(int)PonykartCollidesWithGroups::Karts; if (teCollidesWith&ThingEnum::InvisibleWalls) pcwg|=(int)PonykartCollidesWithGroups::InvisibleWalls; enumPCWGConversionDone: if (pcwg!=(int)teCollidesWith) throw string("Invalid collides-with group!"); collidesWith = (PonykartCollidesWithGroups)pcwg; // update the transforms Matrix4 trans; trans.makeTransform(spawnPosition, spawnScale, spawnOrientation); btTransform btTrans{toBtQuaternion(trans.extractQuaternion()), toBtVector3(trans.getTrans())}; info->m_startWorldTransform = btTrans; motionState->setWorldTransform(btTrans); }
//----------------------------------------------------------------------------------- void PbsMaterial::updateUniforms(const Pass* pass, const AutoParamDataSource* source, const LightList* pLightList) { // Vertex program GpuProgramParametersSharedPtr vertexParams = pass->getVertexProgramParameters(); vertexParams->setIgnoreMissingParams(true); vertexParams->setNamedAutoConstant("mvpMat", GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); vertexParams->setNamedAutoConstant("mvMat", GpuProgramParameters::ACT_WORLDVIEW_MATRIX); // Fragment program GpuProgramParametersSharedPtr fragmentParams = pass->getFragmentProgramParameters(); fragmentParams->setNamedAutoConstant("ivMat", GpuProgramParameters::ACT_INVERSE_VIEW_MATRIX); fragmentParams->setNamedConstant("in_albedo", mAlbedo); fragmentParams->setNamedConstant("in_f0", mF0); fragmentParams->setNamedConstant("in_roughness", mRoughness); fragmentParams->setNamedConstant("in_light_roughness_offset", mLightRoughnessOffset); fragmentParams->setNamedConstant("in_offset_main", mMainOffset); fragmentParams->setNamedConstant("in_scale_main", mMainScale); fragmentParams->setNamedConstant("in_offset_d1", mD1Offset); fragmentParams->setNamedConstant("in_scale_d1", mD1Scale); fragmentParams->setNamedConstant("in_offset_d2", mD2Offset); fragmentParams->setNamedConstant("in_scale_d2", mD2Scale); // Set light uniforms unsigned int count = std::min(mDirectionalLightCount + mPointLightCount + mSpotLightCount, maxLightCount); if (count) { Matrix4 viewMatrix = source->getViewMatrix(); Quaternion viewMatrixQuat = viewMatrix.extractQuaternion(); int directionalLightIndex = 0; int pointLightLightIndex = 0; int spotLightIndex = 0; for (unsigned int i = 0; i < count; i++) { Light* light = (*pLightList)[i]; int index; if (light->getType() == Light::LT_DIRECTIONAL) { index = directionalLightIndex; directionalLightIndex++; } else if (light->getType() == Light::LT_POINT) { index = mDirectionalLightCount + pointLightLightIndex; pointLightLightIndex++; } else { index = mDirectionalLightCount + mPointLightCount + spotLightIndex; spotLightIndex++; } Vector3 pos = viewMatrix * light->getDerivedPosition(); mLightPositions_es[index * 4 + 0] = pos.x; mLightPositions_es[index * 4 + 1] = pos.y; mLightPositions_es[index * 4 + 2] = pos.z; Vector3 dir = -(viewMatrixQuat * light->getDerivedDirection()).normalisedCopy(); mLightDirections_es[index * 4 + 0] = dir.x; mLightDirections_es[index * 4 + 1] = dir.y; mLightDirections_es[index * 4 + 2] = dir.z; ColourValue color = light->getDiffuseColour(); mLightColors[index * 4 + 0] = color.r; mLightColors[index* 4 + 1] = color.g; mLightColors[index* 4 + 2] = color.b; mLightParameters[index * 4 + 0] = light->getAttenuationRange(); mLightParameters[index * 4 + 1] = Math::Cos(light->getSpotlightOuterAngle() / 2.0); mLightParameters[index * 4 + 2] = light->getSpotlightFalloff(); } fragmentParams->setNamedConstant("lightPositions_es", &(mLightPositions_es[0]), count); fragmentParams->setNamedConstant("lightDirections_es", &(mLightDirections_es[0]), count); fragmentParams->setNamedConstant("lightColors", &(mLightColors[0]), count); fragmentParams->setNamedConstant("lightParameters", &(mLightParameters[0]), count); } // update the textures if (_hasSamplerChanged) { for (int i = 0; i < ST_COUNT; i++) { SamplerContainer& s = _samplers[i]; if (s.status == SS_UPDATED) { updateTexturUnits(s.textureUnitState, fragmentParams, s, i); s.status = SS_ACTIVE; } } _hasSamplerChanged = false; } }
void CPlayerInterpolator::onFixedTick(unsigned int msecs) { if( !_transformBuffer.empty() && !_connecting ) { // Posicionamos el grafico y el controlador fisico donde nos indique // el buffer de posiciones interpolado _extrapolatedTicks = 0; Matrix4 newTransform = _transformBuffer.front(); Vector3 newPosition = newTransform.getTrans(); _extrapolatedMotion = (newPosition - _entity->getPosition())*0.5f; _controller->setPhysicPosition( newPosition ); _entity->setOrientation( newTransform.extractQuaternion() ); _transformBuffer.pop_front(); if( !_animationBuffer.empty() ) { if( _animationBuffer.front().tick == _tickCounter ) { // Reproducir animacion AnimInfo info = _animationBuffer.front(); _animationBuffer.pop_front(); // Emitimos el mensaje de animación if(info.stop) { // Mandar animación de stop shared_ptr<CMessageStopAnimation> stopAnimMsg = make_shared<CMessageStopAnimation>(); stopAnimMsg->setString(info.animName); _entity->emitMessage(stopAnimMsg); } else { // Mandar set animation shared_ptr<CMessageSetAnimation> setAnimMsg = make_shared<CMessageSetAnimation>(); setAnimMsg->setAnimation(info.animName); setAnimMsg->setLoop(info.loop); setAnimMsg->setExclude(info.exclude); setAnimMsg->setRewind(info.rewind); _entity->emitMessage(setAnimMsg); } } } if( !_audioBuffer.empty() ) { if( _audioBuffer.front().tick == _tickCounter ) { AudioInfo info = _audioBuffer.front(); _audioBuffer.pop_front(); shared_ptr<CMessageAudio> audioMsg = make_shared<CMessageAudio>(); audioMsg->setAudioName(info.audioName); audioMsg->isLoopable(info.loopSound); audioMsg->is3dSound(info.play3d); audioMsg->streamSound(info.streamSound); audioMsg->stopSound(info.stopSound); _entity->emitMessage(audioMsg); } } if ( !_weaponBuffer.empty() && _weaponBuffer.front().tick == _tickCounter ) { WeaponInfo info = _weaponBuffer.front(); _weaponBuffer.pop_front(); shared_ptr<CMessageChangeWeaponGraphics> weaponMsg = make_shared<CMessageChangeWeaponGraphics>(); weaponMsg->setWeapon(info.weapon); _entity->emitMessage(weaponMsg); } _tickCounter = (_tickCounter + 1) % _ticksPerBuffer; } else { // Estamos ejecutando ticks con el buffer vacio // tendremos que descartar estos ticks del siguiente buffer // recibido if(!_connecting) { if( _extrapolatedTicks < _ticksPerBuffer ) { std::cout << "perdiendo ticks"+ _lostTicks << std::endl; Vector3 newPosition = _entity->getPosition() + _extrapolatedMotion * 0.5f; Physics::CapsuleGeometry controllerGeometry = Physics::CapsuleGeometry( _controller->getCapsuleRadius(), _controller->getCapsuleHeight() / 2.0f ); if( !Physics::CServer::getSingletonPtr()->overlapAny( controllerGeometry, newPosition ) ) { _controller->setPhysicPosition( newPosition ); if( ++_extrapolatedTicks == 2 ) _extrapolatedMotion = Vector3::ZERO; } } } } }