void CAnimatedMeshSceneNode::useAnimationSet(u32 set_num) { if (m_animation_set.empty()) { setFrameLoop(getStartFrame(), getEndFrame()); return; } setFrameLoop(m_animation_set[set_num * 2], m_animation_set[set_num * 2 + 1]); }
void SpaceShip::handleEvents(sf::Event& event, WorldRef& worldRef) { if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::W) { mVelocity.y = -mSpeed; } else if (event.key.code == sf::Keyboard::S) { mVelocity.y = mSpeed; } if (event.key.code == sf::Keyboard::A) { mVelocity.x = -mSpeed; setFrameLoop(0, 0); } else if (event.key.code == sf::Keyboard::D) { mVelocity.x = mSpeed; setFrameLoop(1, 1); } } else if (event.type == sf::Event::KeyReleased) { if (event.key.code == sf::Keyboard::W || event.key.code == sf::Keyboard::S) { mVelocity.y = 0; } else if (event.key.code == sf::Keyboard::A || event.key.code == sf::Keyboard::D) { mVelocity.x = 0; } } else if (event.type == sf::Event::MouseButtonPressed) { if (event.mouseButton.button == sf::Mouse::Left) { for (auto& weap : mWeapons) { weap.fire(worldRef); } } } else if (event.type == sf::Event::MouseMoved) { mMousePosition = sf::Vector2f(event.mouseMove.x, event.mouseMove.y); } }
//! Starts a MD2 animation. bool CAnimatedMeshSceneNode::setMD2Animation(EMD2_ANIMATION_TYPE anim) { if (!Mesh || Mesh->getMeshType() != EAMT_MD2) return false; IAnimatedMeshMD2* m = (IAnimatedMeshMD2*)Mesh; s32 begin, end, speed; m->getFrameLoop(anim, begin, end, speed); setAnimationSpeed( f32(speed) ); setFrameLoop(begin, end); return true; }
//! Starts a special MD2 animation. bool CAnimatedMeshSceneNode::setMD2Animation(const c8* animationName) { if (!Mesh || Mesh->getMeshType() != EAMT_MD2) return false; IAnimatedMeshMD2* m = (IAnimatedMeshMD2*)Mesh; s32 begin, end, speed; if (!m->getFrameLoop(animationName, begin, end, speed)) return false; setAnimationSpeed( (f32)speed ); setFrameLoop(begin, end); return true; }
//! Sets a new mesh void CAnimatedMeshSceneNode::setMesh(IAnimatedMesh* mesh) { if (!mesh) return; // won't set null mesh if (Mesh != mesh) { if (Mesh) Mesh->drop(); Mesh = mesh; // grab the mesh (it's non-null!) Mesh->grab(); } // get materials and bounding box Box = Mesh->getBoundingBox(); IMesh* m = Mesh->getMesh(0,0); if (m) { Materials.clear(); Materials.reallocate(m->getMeshBufferCount()); for (u32 i=0; i<m->getMeshBufferCount(); ++i) { IMeshBuffer* mb = m->getMeshBuffer(i); if (mb) Materials.push_back(mb->getMaterial()); else Materials.push_back(video::SMaterial()); } } // clean up joint nodes if (JointsUsed) { JointsUsed=false; checkJoints(); } // get start and begin time // setAnimationSpeed(Mesh->getAnimationSpeed()); setFrameLoop(0, Mesh->getFrameCount()); }
//! Sets a new mesh void CAnimatedMeshSceneNode::setMesh(IAnimatedMesh* mesh) { if (!mesh) return; // won't set null mesh if (Mesh) Mesh->drop(); Mesh = mesh; // get materials and bounding box Box = Mesh->getBoundingBox(); IMesh* m = Mesh->getMesh(0,0); if (m) { Materials.clear(); video::SMaterial mat; for (u32 i=0; i<m->getMeshBufferCount(); ++i) { IMeshBuffer* mb = m->getMeshBuffer(i); if (mb) mat = mb->getMaterial(); Materials.push_back(mat); } } // get start and begin time setFrameLoop ( 0, Mesh->getFrameCount() ); // grab the mesh if (Mesh) Mesh->grab(); }