ISceneNode* Render::createNode(bool isMD2, IAnimatedMesh* mesh, ITexture* texture, bool light,core::vector3df scale, core::vector3df pos, core::vector3df rotation) { IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh, NULL, IDFlag_IsPickable); if(node) { pos.Y += -node->getBoundingBox().MinEdge.Y * scale.Y; node->setPosition(pos); node->setRotation(rotation); node->setScale(scale); node->setAnimationSpeed(20.f); scene::ITriangleSelector* selector = 0; selector = smgr->createTriangleSelector(node); node->setTriangleSelector(selector); selector->drop(); //Autoscale //f32 scale = 0.25f; node->setScale(scale); if (texture) { //node->setMaterialFlag(EMF_LIGHTING, false); node->setMaterialTexture(0, texture); } node->setMD2Animation(EMAT_STAND); } return node; }
void CScene::UpdateScene(vector<vector3df> otherClientPosition, ICameraSceneNode* camera) { ISceneManager* smgr=device->getSceneManager(); IVideoDriver* driver=device->getVideoDriver(); // 测试用 IAnimatedMesh* personMeshTest=smgr->getMesh("../../media/sydney.md2"); IAnimatedMeshSceneNode* personNode = smgr->addAnimatedMeshSceneNode( personMeshTest ); if (!personMeshTest) { device->drop(); return ; } if (personNode) { personNode->setScale(vector3df(0.4f,0.4f,0.4f)); personNode->setPosition(vector3df(0.0f,10.0f,0.0f)); personNode->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") ); personNode->setMaterialFlag(EMF_LIGHTING, false); personNode->getMaterial(0).Shininess=28.0f; personNode->getMaterial(0).NormalizeNormals=true; personNode->setMD2Animation ( scene::EMAT_STAND ); } personMeshTest->setMaterialFlag(EMF_LIGHTING,false); // 显示其他客户端 for (int i=0;i!=otherClientPosition.size();i++) { IAnimatedMesh* personMesh=smgr->getMesh("../../media/sydney.md2"); IAnimatedMeshSceneNode* personNode = smgr->addAnimatedMeshSceneNode( personMesh ); if (!personMesh) { device->drop(); return ; } if (personNode && personNode->getPosition()!=camera->getPosition()) { // personNode->setPosition(vector3df(10,20,0)); // personNode->setScale(vector3df(0.5,0.5,0.5)); personNode->setPosition(otherClientPosition[i]); personNode->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") ); personNode->setMaterialFlag(EMF_LIGHTING, false); personNode->getMaterial(0).Shininess=28.0f; personNode->getMaterial(0).NormalizeNormals=true; personNode->setMD2Animation ( scene::EMAT_STAND ); } personMesh->setMaterialFlag(EMF_LIGHTING,false); } }
IAnimatedMeshSceneNode* MyIrrlichtComposition::mLoadMesh(vector3df pos,vector3df rot,vector3df scale, std::string name1, std::string name2) { IAnimatedMeshSceneNode* obj = smgr->addAnimatedMeshSceneNode(smgr->getMesh(name1.c_str())); if(obj) { obj->setPosition(pos); obj->setMD2Animation(scene::EMAT_RUN); obj->setRotation(rot); obj->setScale(scale); obj->setMaterialTexture(0, driver->getTexture(name2.c_str())); obj->addShadowVolumeSceneNode(); return obj; } else exit(2); }
void Unit::addModel() { IAnimatedMeshSceneNode* modelNode = Game::getInstance().sceneManager->addAnimatedMeshSceneNode( model, node ); if (modelNode) { modelNode->setMaterialTexture( 0, texture ); modelNode->getMaterial(0).Shininess = 0; modelNode->setScale(vector3df(0.15f, 0.15f, 0.15f) ); modelNode->addShadowVolumeSceneNode(0, 0, false); modelNode->setID(0); currentAnimation = IDLE_ANIMATION; float randX = rand() % 8 - 4; float randZ =rand() % 8 - 4; modelNode->setPosition(vector3df(randX, 0.0f, randZ)); } modelNodes.push_back(modelNode); }
void AnnyFactory::produce(int x,int y,int z){ std::string sydneyMesh = "monkey.obj"; std::string sydneyMaterial = "unwrappedPainted.png";//"monkey.bmp"; IAnimatedMesh* mesh = sceneManager->getMesh((RESOURCES+sydneyMesh).c_str()); if (!mesh) { exit(1); } IAnimatedMeshSceneNode* node = sceneManager->addAnimatedMeshSceneNode( mesh ); const wchar_t* name = L"Monkey head"; objectList->addObject(name); if (node) { node->setMaterialFlag(EMF_LIGHTING, false); node->setMD2Animation(scene::EMAT_RUN); node->setMaterialTexture( 0, driver->getTexture((RESOURCES+sydneyMaterial).c_str()) ); node->setName(name); node->setPosition(core::vector3df(x,y,z)); node->setScale(core::vector3df(10,10,10)); node->setRotation(core::vector3df(0,200,0)); } }
void CCharacterExample::runExample() { for(s32 i=0; i<KEY_KEY_CODES_COUNT; i++) KeyIsDown[i] = false; debugDraw = true; drawProperties = true; drawWireFrame = false; rows = 10; columns = 10; device = createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16, false, false, false, this); device->setWindowCaption(L"irrBullet Character Example - Josiah Hartzell"); device->getFileSystem()->addFileArchive("./media/"); device->getSceneManager()->addLightSceneNode(0, vector3df(20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f); //////////////////////////// // Create irrBullet World // //////////////////////////// world = createIrrBulletWorld(device, true, debugDraw); world->setDebugMode(EPDM_DrawAabb | EPDM_DrawContactPoints); world->setGravity(vector3df(0,-10,0)); camera = device->getSceneManager()->addCameraSceneNodeMaya(); camera->setPosition(vector3df(50,15,200)); camera->bindTargetAndRotation(true); createGround(); createBoxes(); IKinematicCharacterController* character = new IKinematicCharacterController(world); IAnimatedMeshSceneNode* sydney = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("sydney.md2")); sydney->setScale(vector3df(0.14,0.14,0.14)); sydney->getMaterial(0).setTexture(0, device->getVideoDriver()->getTexture("sydney.bmp")); sydney->setMD2Animation(scene::EMAT_STAND); // Set our delta time and time stamp u32 TimeStamp = device->getTimer()->getTime(); u32 DeltaTime = 0; EMD2_ANIMATION_TYPE animation = EMAT_STAND; EMD2_ANIMATION_TYPE newAnimation = EMAT_RUN; bool jump = false; while(device->run()) { device->getVideoDriver()->beginScene(true, true, SColor(255,100,101,140)); DeltaTime = device->getTimer()->getTime() - TimeStamp; TimeStamp = device->getTimer()->getTime(); /*sydney->setPosition(character->getWorldTransform().getTranslation()+vector3df(0,-((sydney->getBoundingBox().MaxEdge.Y-sydney->getBoundingBox().MinEdge.Y)*0.1*0.5f),0)); vector3df dir = camera->getAbsolutePosition()-sydney->getAbsolutePosition(); dir.normalize(); dir.Y = 0; dir *= -1; character->setWalkDirection(dir*0.3f);*/ if(IsKeyDown(KEY_KEY_W)) { DirZ = -1.0f; } else if(IsKeyDown(KEY_KEY_S)) { DirZ = 1.0f; } else { DirZ = 0.0f; } if(IsKeyDown(KEY_KEY_A)) { DirX = 1.0f; } else if(IsKeyDown(KEY_KEY_D)) { DirX = -1.0f; } else { DirX = 0.0f; } if(IsKeyDown(KEY_SPACE)) { character->jump(); jump = true; } if(DirZ != 0 || DirX != 0) newAnimation = EMAT_RUN; else newAnimation = EMAT_STAND; if(!character->isOnGround()) { newAnimation = jump ? EMAT_JUMP:EMAT_CROUCH_STAND; } else jump = false; if(animation != newAnimation) { animation = newAnimation; sydney->setMD2Animation(animation); } sydney->setPosition(character->getWorldTransform().getTranslation()); vector3df rot(0, camera->getRotation().Y-90.0f, 0); sydney->setRotation(rot); vector3df direction(DirX, 0.0f, DirZ); irr::core::matrix4 m; m.setRotationDegrees(vector3df(0, camera->getRotation().Y-180.0f, 0)); m.transformVect(direction); character->setPositionIncrementPerSimulatorStep(direction*0.3f); camera->setTarget(sydney->getPosition()); // Step the simulation with our delta time world->stepSimulation(DeltaTime*0.001f, 120); world->debugDrawWorld(debugDraw); // This call will draw the technical properties of the physics simulation // to the GUI environment. world->debugDrawProperties(true); device->getSceneManager()->drawAll(); device->getGUIEnvironment()->drawAll(); device->getVideoDriver()->endScene(); } delete character; // We're done with the IrrBullet world, so we free the memory that it takes up. if(world) delete world; if(device) device->drop(); }
int main() { /* shadowDimen = dimension2du(1024,1024); shadowDimen = dimension2du(2048,2048); shadowDimen = dimension2du(4096,4096); shadowDimen = dimension2du(2048,2048); filterType = EFT_NONE; filterType = EFT_4PCF; filterType = EFT_8PCF; filterType = EFT_4PCF; */ dimension2du shadowDimen = dimension2du(1024,1024); E_FILTER_TYPE filterType = EFT_4PCF; filterType = EFT_NONE; //// IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2du(800,600),32); ISceneManager* smgr = device->getSceneManager(); IVideoDriver* driver = device->getVideoDriver(); ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0,100,.5); cam->setPosition(vector3df(0,10,0)); // Create the effect handler, passing the device and RTT size (as a dimension2d) . effectHandler* effect = new effectHandler(device,shadowDimen); ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/terrain.bmp",0,-1,vector3df(0,0,0),vector3df(0,0,0),vector3df(1,1,1),SColor(255,255,255,255),1,ETPS_33); terrain->setMaterialTexture(0,driver->getTexture("media/terrain.jpg")); terrain->setMaterialTexture(1, driver->getTexture("media/detailmap.jpg")); terrain->scaleTexture(1,10); terrain->setScale(core::vector3df(4, 0.01f, 4)); terrain->setPosition(vector3df(-120,-1.5f,-120)); terrain->setMaterialType(EMT_DETAIL_MAP); // Make the terrain recieve a shadow with the specified filter type. // (NOTE: 12PCF is only available in Direct3D9, all others work with OpenGL) effect->addShadowToNode(terrain,filterType); IAnimatedMeshSceneNode* sydney; IAnimatedMesh* sydneymesh = smgr->getMesh("media/dwarf.x"); for(int g = 0;g < 1;g++) { for(int v = 0;v < 3;v++) { sydney = smgr->addAnimatedMeshSceneNode(sydneymesh); sydney->setScale(vector3df(0.05f,0.05f,0.05f)); sydney->setPosition(vector3df(g * 4,0.5f,v * 4)); sydney->setMaterialFlag(EMF_NORMALIZE_NORMALS,true); sydney->setAutomaticCulling(EAC_FRUSTUM_BOX); sydney->setMaterialType(EMT_SOLID); // Add the nodes to the depth pass so that they cast a shadow. effect->addNodeToDepthPass(sydney); } } effect->getLightCamera()->addAnimator(smgr->createFlyCircleAnimator(sydney->getPosition() + vector3df(0,15,0),25,0.0002f)); effect->getLightCamera()->setNearValue(5); effect->setMaxShadowDistanceFromLight(120); smgr->addLightSceneNode(effect->getLightCamera()); MyEventReceiver receiver(cam); device->setEventReceiver(&receiver); // Parent a sphere to the light camera so we can see its position. smgr->addSphereSceneNode(1,8,effect->getLightCamera())->setMaterialFlag(EMF_LIGHTING,false); while(device->run()) { wchar_t tmp[255]; swprintf(tmp,255,L"Shadow Map Demo (FPS: %d)",driver->getFPS()); device->setWindowCaption(tmp); driver->beginScene(true,true,SColor(0,0,0,0)); // Point the light camera at one of the nodes as it rotates around them. effect->setLightTarget(sydney->getPosition()); // Update the effect handler, remember to always do this BEFORE smgr->drawAll and AFTER beginscene! effect->update(); smgr->drawAll(); // If user wishes we can display the shadow map to the screen. (May not work in OpenGL) if(disp2d) driver->draw2DImage(effect->getShadowMapTexture(),position2d<s32>(0,0)); driver->endScene(); // device->sleep(5); } device->drop(); return 0; }