int main(int argc, char **argv) { BSPdungeon dun(50,50,5); IrrlichtDevice *device =createDevice( video::EDT_OPENGL, dimension2d<u32>(1280,720), 16,false, false, false, 0); if (!device) return 1; device->setWindowCaption(L"Pangolin Kwest"); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1)); ILightSceneNode* mylight1 = smgr->addLightSceneNode( 0, core::vector3df(00,00,00), video::SColorf(0.3f,0.3f,0.3f), 30.0f, 1 ); //IGUIFont* myfont=guienv->getFont("./myfont.xml"); //if(myfont==0)exit(93); //guienv->addMessageBox(L"Alertz!",L"You pangolin are been createrized. You totalleh ready to bash monstaz etc.!"); mylight1->enableCastShadow(true); //guienv->addStaticText(L"Pangolin Kwest 3D",rect<s32>(10,10,260,22), true); //------------------------------------------- int x,y,z; for(x=0;x<50;x++){ for(y=0;y<50;y++){ if(dun.map[x][y]==NIL){ for(z=0;z<3;z++){ ISceneNode* cueb=smgr->addCubeSceneNode(10); cueb->setMaterialFlag(EMF_LIGHTING, true); cueb->setMaterialTexture( 0, driver->getTexture("media/stdwall.jpg") ); // cueb->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25,0.5); // cueb->getMaterial(0).getTextureMatrix(0).setTextureScale(0.0625,0.0625); cueb->setPosition(vector3df(x*10,z*10,y*10)); } } // ISceneNode* cueb=smgr->addCubeSceneNode(10); // cueb->setMaterialFlag(EMF_LIGHTING, true); // cueb->setMaterialTexture( 0, driver->getTexture("media/stdfloor.jpg") ); // cueb->setPosition(vector3df(x*10,-10,y*10)); ISceneNode* cueb=smgr->addCubeSceneNode(10); cueb->setMaterialFlag(EMF_LIGHTING, true); cueb->setMaterialTexture( 0, driver->getTexture("media/stdup.jpg") ); cueb->setPosition(vector3df(x*10,30,y*10)); } } ISceneNode* cueb=smgr->addCubeSceneNode(500); cueb->setMaterialFlag(EMF_LIGHTING, true); cueb->setMaterialTexture( 0, driver->getTexture("media/stdfloor.jpg") ); cueb->setPosition(vector3df(250,-255,250)); //cueb->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25,0.5); cueb->getMaterial(0).getTextureMatrix(0).setTextureScale(50,50); //cueb->setScale(vector3df(0,-5,0)); //cueb->addshadowVolumeSceneNode(); //------------------------------------------- int lastFPS; //smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0)); ICameraSceneNode* mycam; mycam=smgr->addCameraSceneNodeFPS(0,100.0f,0.025f); mycam->setFOV(45); mylight1->setParent(mycam); while(device->run()) { //mylight1->setPosition(); //mylight1-> driver->beginScene(true, true, SColor(255,100,101,140)); smgr->drawAll(); guienv->drawAll(); driver->endScene(); int fps = driver->getFPS(); if (lastFPS != fps) { core::stringw str = L"Pangolin Kwest 3D ["; str += driver->getName(); str += "] FPS:"; str += fps; device->setWindowCaption(str.c_str()); lastFPS = fps; } } device->drop(); return 0; }
int main() { EventHandler eventHandler; irrlicht = createDevice( video::EDT_OPENGL, dimension2d<u32>(800, 600), 32, false, false, false, &eventHandler); if (!irrlicht) { return 1; } pdp::initTemplates(); irrlicht->setWindowCaption(L"Procedural Death Planet"); IVideoDriver* driver = irrlicht->getVideoDriver(); ISceneManager* smgr = irrlicht->getSceneManager(); IGUIEnvironment* guienv = irrlicht->getGUIEnvironment(); pdp::VehicleDesign *design = pdp::getPatentOffice()->getVehicleDesign(pdp::getPlayerVehicle()); if (design) { player = spawnVehicle(design, vector3df(0.0f)); } ICameraSceneNode *camera = smgr->addCameraSceneNode( 0, vector3df( 0, 8, -20 ), vector3df( 0, 1, 0 ) ); camera->setFOV( 0.34906585f ); u32 prevT = irrlicht->getTimer()->getTime(); float speed = 10.f; float turn_speed = 100.f; while (irrlicht->run()) { const u32 t = irrlicht->getTimer()->getTime(); float deltaT = (t - prevT) / 1000.f; prevT = t; float theta = 0.f; bool ctrl = eventHandler.IsKeyDown(KEY_LSHIFT); if (eventHandler.IsKeyDown(KEY_LEFT)) { theta -= deltaT * turn_speed * clamp(speed / 30.f, 0.f, 1.f); vector3df rot = (ctrl ? playerTurret : player)->getRotation(); rot.Y += theta; if (rot.Y < 0.0f) { rot.Y += 360.0f; } (ctrl ? playerTurret : player)->setRotation( rot ); } else if (eventHandler.IsKeyDown(KEY_RIGHT)) { theta += deltaT * turn_speed * clamp(speed / 30.f, 0.f, 1.f); vector3df rot = (ctrl ? playerTurret : player)->getRotation(); rot.Y += theta; if (rot.Y >= 360.0) { rot.Y -= 360.0f; } (ctrl ? playerTurret : player)->setRotation( rot ); } driver->beginScene( true, true, SColor(255,100,101,140) ); smgr->drawAll(); guienv->drawAll(); driver->endScene(); } irrlicht->drop(); return 0; }
void Mesh3DInitScene() { IAnimatedMesh* mesh; IAnimatedMeshSceneNode* node; scene::ISceneNodeAnimator* anim; scene::ISceneManager* smgr = IrrlichtManager::GetIrrlichtManager()->GetScene(); IrrlichtDevice* device = IrrlichtManager::GetIrrlichtManager()->GetDevice(); video::IVideoDriver* driver = IrrlichtManager::GetIrrlichtManager()->GetDriver(); std::string load_zip; std::string load_data; std::string reload_path; FileSystemZip* pfilesystem = NULL; io::IReadFile* memfile = NULL; byte* apk_buffer = NULL; byte* buff_extract = NULL; int size = 0; int apk_size = 0; if (!IrrlichtManager::GetIrrlichtManager()->GetDevice()) { LogError("Error initializing Irrlicht"); return; } IrrlichtManager::GetIrrlichtManager()->GetDevice()->getTimer()->setTime(0); smgr->addLightSceneNode(0, core::vector3df(-100,10,0), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f); smgr->addLightSceneNode(0, core::vector3df(+100,10,0), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f); //////////////////////////////mesh///////////////////////////////////////////////// load_zip = (GetBaseAppPath() + "game/ninja.zip").c_str(); load_data = "ninja.b3d"; reload_path = (GetBaseAppPath() + "game/ninja.b3d").c_str(); #ifdef ANDROID_NDK apk_buffer = FileManager::GetFileManager()->Get(load_zip.c_str(), &apk_size, false, false); if( apk_buffer ) { pfilesystem = new FileSystemZip(); pfilesystem->Init_unzMemory(apk_buffer, apk_size); buff_extract = pfilesystem->Get_unz(load_data, &size); delete apk_buffer; apk_buffer = NULL; } #else pfilesystem = new FileSystemZip(); pfilesystem->Init_unz(load_zip.c_str()); buff_extract = pfilesystem->Get_unz(load_data.c_str(), &size); #endif memfile = device->getFileSystem()->createMemoryReadFile(buff_extract, size, reload_path.c_str(), true); //new buffer copy on file->read(Buffer, size) of CXMeshFileLoader::readFileIntoMemory mesh = smgr->getMesh( memfile ); node = smgr->addAnimatedMeshSceneNode( mesh ); //delete buff_extract in drop() then goto ~CMemoryReadFile memfile->drop(); if( pfilesystem ) { delete pfilesystem; pfilesystem = NULL; } //////////////////////////////texture///////////////////////////////////////////////// node->setMaterialTexture( 0, driver->getTexture((GetBaseAppPath()+"game/nskinbl.jpg").c_str()) ); node->setMaterialFlag(EMF_LIGHTING, true); node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true); anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0)); node->addAnimator(anim); anim->drop(); u32 alpha_val = 90; u32 MaterialCount = node->getMaterialCount(); for(u32 i=0; i<MaterialCount; i++) { video::SMaterial& tex_mat = node->getMaterial(i); tex_mat.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; //tex_mat.MaterialTypeParam = 0.1; //tex_mat.MaterialTypeParam2= 0.1; tex_mat.AmbientColor.setAlpha(alpha_val); tex_mat.DiffuseColor.setAlpha(alpha_val); tex_mat.SpecularColor.setAlpha(alpha_val); tex_mat.EmissiveColor.setAlpha(alpha_val); } #if defined(_IRR_COMPILE_WITH_OGLES2_) for(u32 i=0; i<mesh->getMeshBufferCount(); i++) { scene::IMeshBuffer* buffer = mesh->getMeshBuffer(i); video::S3DVertex* vertex = (video::S3DVertex*)buffer->getVertices(); for(u32 j=0; j<buffer->getVertexCount(); j++) { vertex[j].Color.setAlpha(alpha_val); } } #endif smgr->addSkyBoxSceneNode(IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_up.jpg"), IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_dn.jpg"), IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_lf.jpg"), IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_rt.jpg"), IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_ft.jpg"), IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_bk.jpg")); //////////////////////////////////cam///////////////////////////////////////////// ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, .02f, 0, 0, 0, true, 1.0f); //camera->addCameraSceneNode(0, vector3df(0,2,-10)); camera->setPosition(core::vector3df(0,5,-20)); float fov = float(GetPrimaryGLX())/ float(GetPrimaryGLY()); camera->setAspectRatio(fov); camera->setFOV((120 * (float)M_PI / 360.0f)); #ifdef _IRR_COMPILE_WITH_GUI_ EventControlComponent* receiver = new EventControlComponent(); receiver->AddGuiButton(); device->setEventReceiver(receiver); #endif }
void loop_ctr(s4 &game_state) { ISceneNode* empty_node = irrlicht->smgr->addEmptySceneNode(); empty_node->setPosition(vector3df(0,0,0)); ICameraSceneNode* camera = irrlicht->smgr->addCameraSceneNode(); camera->setPosition({0,-250,-100}); camera->setUpVector({0,0,-1}); camera->setTarget({0,0,0}); camera->setParent(empty_node); camera->setFOV(70); irrlicht->device->getCursorControl()->setVisible(false); irrlicht->smgr->setAmbientLight(SColorf(1,1,1,1)); irrlicht->hud = irrlicht->smgr->createNewSceneManager(false); ICameraSceneNode* hud_camera = irrlicht->hud->addCameraSceneNode(); matrix4 ortho; ortho.buildProjectionMatrixOrthoLH( irrlicht->driver->getScreenSize().Width/ortho_scale, irrlicht->driver->getScreenSize().Height/ortho_scale,-1.0,1000.0); hud_camera->setProjectionMatrix(ortho); hud_camera->setPosition({0,0,-100}); hud_camera->setTarget({0,0,0}); // temp objects ---------------------------------- blist cmpnt_list, joint_list, tree_list; b_set(cmpnt_list,memory,sizeof(Component)); b_set(joint_list,memory,sizeof(Joint)); b_set(tree_list,memory,sizeof(CTree)); irr::core::map<ISceneNode*,Component*> node_cmpnt_map; ISceneNode* ctr_parent = irrlicht->smgr->addEmptySceneNode(); IMesh* cube_mesh = irrlicht->smgr->getGeometryCreator()->createCubeMesh(); auto add_object_to_world = [&] (vec3 pos, vec3 scale, s4 a, s4 r, s4 g, s4 b) -> Component* { const f4 floor_position = 10.0f; Component make_cmpnt; make_cmpnt.id = CMPNT_ID; CMPNT_ID++; make_cmpnt.node = irrlicht->smgr->addMeshSceneNode(cube_mesh,ctr_parent); make_cmpnt.node->setPosition(pos.irr()); make_cmpnt.node->setScale(scale.irr()); make_cmpnt.node->getMaterial(0).AmbientColor.set(a,r,g,b); make_cmpnt.shadow = irrlicht->smgr->addMeshSceneNode(cube_mesh,0); make_cmpnt.shadow->setScale({scale.x, scale.y, 0.1f}); make_cmpnt.shadow->setPosition({pos.x, pos.y,floor_position}); make_cmpnt.shadow->getMaterial(0).AmbientColor.set(GREY_BLUE_SHADOW); for (s4 i = 0; i < MAX_JOINTS; i++) make_cmpnt.joints[i] = 0; make_cmpnt.tree = 0; b_copy(cmpnt_list,&make_cmpnt); node_cmpnt_map.insert(make_cmpnt.node, (Component*)blast_address(cmpnt_list) ); return (Component*)blast_address(cmpnt_list); }; auto add_joint = [&] (Component* A, Component* B, vec3 posA, vec3 posB) { Joint C; C.A = A; C.posA = A->node->getTransformedBoundingBox().getExtent() * A->node->getScale(); C.posA *= (posA * 0.5f); C.B = B; C.posB = B->node->getTransformedBoundingBox().getExtent() * B->node->getScale(); C.posB *= (posB * 0.5f); C.type = Joint::SNAP; C.is_connected = false; b_copy(joint_list,&C); for (s4 i = 0; i < MAX_JOINTS; i++) { if (C.A->joints[i] == 0) { C.A->joints[i] = (Joint*)blast_address(joint_list); break; } else if (i == MAX_JOINTS-1) { std::cout << "ERROR: Joint could not be added to C.A." << std::endl; } } for (s4 i = 0; i < MAX_JOINTS; i++) { if (C.B->joints[i] == 0) { C.B->joints[i] = (Joint*)blast_address(joint_list); break; } else if (i == MAX_JOINTS-1) { std::cout << "ERROR: Joint could not be added to C.B." << std::endl; } } }; { Component* A = add_object_to_world(vec3(0,30,-20),vec3(3,3,3),BLUE_LIGHT); Component* B = add_object_to_world(vec3(0,60,-20),vec3(9,3,2),BLACK); add_joint(A,B,vec3(0.0f,0.0f,1.0f),vec3(0.0f,0.0f,-1.0f)); Component* C = add_object_to_world(vec3(0,-90,-20),vec3(3,3,3),YELLOW_LIGHT); Component* D = add_object_to_world(vec3(0,-40,-20),vec3(8,10,4),GREEN_LIGHT); add_joint(C,D,vec3(0.0f,1.0f,0.0f),vec3(0.0f,-1.0f,0.0f)); add_joint(A,D,vec3(0.0f,0.0f,-1.0f),vec3(0.0f,0.0f,1.0f)); } // temp objects ---------------------------------- SimpleNodeEditor* sneditor = simple_node_editor_init(); sneditor->root_node = ctr_parent; f4 target_z_rotation = empty_node->getRotation().Z; p("---- Game loop start ----"); f4 dt = 0.0f; const f4 maxDelta = 1.0f/60.0f * 5.0f; const f4 tick_ms = 0.01666f; f4 render_dt = 0.0f; const f4 render_ms = 0.016667f; u4 time_physics_prev = btclock->getTimeMicroseconds(); while(irrlicht->device->run() && game_state == GAME_STATE_PLAY) { const u4 time_physics_curr = btclock->getTimeMicroseconds(); const f4 frameTime = ((f4)(time_physics_curr - time_physics_prev)) / 1000000.0; // todo: is this truncated correctly? time_physics_prev = time_physics_curr; f4 capped_dt = frameTime; if (capped_dt > maxDelta) { capped_dt = maxDelta; } render_dt += capped_dt; if ( render_dt >= render_ms ) { render_dt = 0.0f; f4 curr_rotation = empty_node->getRotation().Z; if (curr_rotation != target_z_rotation) { weighted_average(curr_rotation,target_z_rotation, 20.0f); if (curr_rotation >= 360.0f) { curr_rotation -= 360.0f; target_z_rotation -= 360.0f; } else if (curr_rotation < 0) { curr_rotation += 360.0f; target_z_rotation += 360.0f; } empty_node->setRotation({0,0,curr_rotation}); } if (sneditor->selected_node) { position2d<s32> screen_coord = irrlicht->colmgr->getScreenCoordinatesFrom3DPosition(sneditor->selected_node->getPosition(), camera); sneditor->hand_icon->setPosition({(screen_coord.X - (SCREEN_WIDTH/2)) / ortho_scale, (screen_coord.Y - (SCREEN_HEIGHT/2)) / -ortho_scale,0}); } else { sneditor->hand_icon->setPosition({(sneditor->cursor->getPosition().X - (SCREEN_WIDTH/2)) / ortho_scale, (sneditor->cursor->getPosition().Y - (SCREEN_HEIGHT/2)) / -ortho_scale,0}); } // Render irrlicht->driver->beginScene(true, true, SColor(GREY_BLUE)); irrlicht->smgr->drawAll(); irrlicht->driver->clearZBuffer(); irrlicht->hud->drawAll(); irrlicht->driver->endScene(); } dt += capped_dt; while( dt >= tick_ms ) { dt -= tick_ms; receiver->input(); if (receiver->a.state) target_z_rotation -= 90.0f; if (receiver->d.state) target_z_rotation += 90.0f; simple_node_editor_update( sneditor, receiver->mouse.left.state, receiver->mouse.left.released, receiver->mouse.right.state, false, receiver->tab.state, camera, &node_cmpnt_map); // TODO: Change this to: // - only test what the user is holding // - and only if the user is holding the smaller inserting part. // example: holding a screw in a large box bloop(joint_list, i) { Joint* c = (Joint*)b_get_mem_address(joint_list,i); if (c->A->tree != sneditor->selected_tree && c->B->tree != sneditor->selected_tree ) { continue; } if (!c->is_connected) { vec3 A = c->A->node->getPosition(); vec3 B = c->B->node->getPosition(); A += c->posA; B += c->posB; if (A.distance(B) < 13 /* && receiver->spacebar*/) { std::cout << "Comparing " << i << std::endl; c->is_connected = true; connect_joints(c,sneditor,camera,tree_list); } } } bloop(tree_list, i) { CTree* tree = (CTree*)b_get_mem_address(tree_list,i); if (tree->translation == vec3(0,0,0)) { continue; } for (s4 k = 0; k < tree->child_list.length;k++) { Component* cmpnt = (Component*)b_get_value(tree->child_list,k); cmpnt->node->setPosition(cmpnt->node->getPosition() + tree->translation.irr()); cmpnt->shadow->setPosition(cmpnt->node->getPosition() * vector3df(1,1,0) + vector3df(0,0,10)); } tree->translation = vec3(0,0,0); } if (receiver->restart.state) { game_state = GAME_STATE_RESET; } if (receiver->QUIT) { game_state = GAME_STATE_QUIT; } }
void Mesh3DInitScene() { IAnimatedMesh* mesh; IAnimatedMeshSceneNode* node; scene::ISceneNodeAnimator* anim; scene::ISceneManager* smgr = IrrlichtManager::GetIrrlichtManager()->GetScene(); IrrlichtDevice* device = IrrlichtManager::GetIrrlichtManager()->GetDevice(); video::IVideoDriver* driver = IrrlichtManager::GetIrrlichtManager()->GetDriver(); std::string load_zip; std::string load_data; std::string reload_path; FileSystemZip* pfilesystem = NULL; io::IReadFile* memfile = NULL; byte* apk_buffer = NULL; byte* buff_extract = NULL; int size = 0; int apk_size = 0; if (!IrrlichtManager::GetIrrlichtManager()->GetDevice()) { LogError("Error initializing Irrlicht"); return; } IrrlichtManager::GetIrrlichtManager()->GetDevice()->getTimer()->setTime(0); smgr->addLightSceneNode(0, core::vector3df(-100,10,0), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f); smgr->addLightSceneNode(0, core::vector3df(+100,10,0), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f); //////////////////////////////mesh///////////////////////////////////////////////// load_zip = (GetBaseAppPath() + "game/squirrel.zip").c_str(); load_data = "squirrel.x"; reload_path = (GetBaseAppPath() + "game/squirrel.x").c_str(); #ifdef ANDROID_NDK apk_buffer = FileManager::GetFileManager()->Get(load_zip.c_str(), &apk_size, false, false); if( apk_buffer ) { pfilesystem = new FileSystemZip(); pfilesystem->Init_unzMemory(apk_buffer, apk_size); buff_extract = pfilesystem->Get_unz(load_data, &size); delete apk_buffer; apk_buffer = NULL; } #else pfilesystem = new FileSystemZip(); pfilesystem->Init_unz(load_zip.c_str()); buff_extract = pfilesystem->Get_unz(load_data.c_str(), &size); #endif memfile = device->getFileSystem()->createMemoryReadFile(buff_extract, size, reload_path.c_str(), true); //new buffer copy on file->read(Buffer, size) of CXMeshFileLoader::readFileIntoMemory mesh = smgr->getMesh( memfile ); node = smgr->addAnimatedMeshSceneNode( mesh ); //delete buff_extract in drop() then goto ~CMemoryReadFile memfile->drop(); if( pfilesystem ) { delete pfilesystem; pfilesystem = NULL; } //////////////////////////////texture///////////////////////////////////////////////// node->setMaterialTexture( 0, driver->getTexture((GetBaseAppPath()+"game/squirrel_skin.jpg").c_str()) ); node->setMaterialFlag(EMF_LIGHTING, true); node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true); anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0)); node->addAnimator(anim); anim->drop(); //////////////////////////////////cam///////////////////////////////////////////// ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, .02f, 0, 0, 0, true, 1.0f); //camera->addCameraSceneNode(0, vector3df(0,2,-10)); camera->setPosition(core::vector3df(0,2,-10)); float fov = float(GetPrimaryGLX())/ float(GetPrimaryGLY()); camera->setAspectRatio(fov); camera->setFOV((120 * M_PI / 360.0f)); #ifdef _IRR_COMPILE_WITH_GUI_ EventControlComponent* receiver = new EventControlComponent(); receiver->AddGuiButton(); device->setEventReceiver(receiver); #endif }