Пример #1
0
//-------------------------------------------------------------------------------------------------
bool sdPhysicsSystem::LoadScene(sdMap* pkMap)
{
	if (!m_bInitialized || !pkMap)
		return false;

	sdTerrain* pkTerrain = pkMap->GetTerrain();
	NIASSERT(pkTerrain);

	// 创建空白NxScene
	CreateEmptyScene(pkTerrain->GetTerrainSize());
	NIASSERT(m_pkScene);

	float fTimeStep = 1.f / 60.f;
	m_pkScene->setTiming(fTimeStep, 6, NX_TIMESTEP_FIXED);
	m_pkScene->setUserTriggerReport(m_pkUserTriggerReport);

	NxMaterial* pkDefaultMaterial = m_pkScene->getMaterialFromIndex(0);
	NIASSERT(pkDefaultMaterial);
	pkDefaultMaterial->setRestitution(0.1f);
	pkDefaultMaterial->setStaticFriction(0.5f);
	pkDefaultMaterial->setDynamicFriction(0.5f);

	// 加载地形数据到NxScene
	CreateTerrain(pkTerrain);

	// 加载预生成的物件数据到NxScene
	

	// 生成地形的边界
	CreateTerrainBound(pkTerrain);

	return true;
}
Пример #2
0
// Initialize the region. This takes a global description and creates the scene node that will be
// the base for the region an, if needed, creates the water level.
void Region::Init( double globalX, double globalY, double globalZ, float sizeX, float sizeY, float waterHeight) {
	LG::Log("Region::Init: r=%s, <%lf,%lf,%lf>", this->Name.c_str(), globalX, globalY, globalZ);
	this->GlobalX = globalX;
	this->GlobalY = globalY;
	this->GlobalZ = globalZ;
	this->LocalX = (float)globalX;
	this->LocalY = (float)globalY;
	this->LocalZ = (float)globalZ;
	// create scene Node
	Ogre::Quaternion orient = Ogre::Quaternion(Ogre::Radian(-3.14159265f/2.0f), Ogre::Vector3(1.0f, 0.0f, 0.0f));
	Ogre::SceneNode* regionNode = LG::RendererOgre::Instance()->CreateSceneNode(this->Name.c_str(), 
			(Ogre::SceneNode*)NULL, false, true, this->LocalX, this->LocalY, this->LocalZ, 
			1.0, 1.0, 1.0, orient.w, orient.x, orient.y, orient.z);
	// add ocean to the region

	Ogre::SceneNode* oceanSceneNode = CreateOcean(regionNode, sizeX, sizeY, waterHeight, "Water/" + this->Name);
	this->OceanSceneNode = oceanSceneNode;
	this->OceanHeight = waterHeight;
	
	Ogre::SceneNode* terrainSceneNode = CreateTerrain(regionNode, sizeX, sizeY, "Terrain/" + this->Name);
	this->TerrainSceneNode = terrainSceneNode;

	this->AddRegionSceneNode(regionNode, LG::RegionRezCodeHigh);
	// m_visCalc->RecalculateVisibility();
	return;
}
Пример #3
0
    bool EnvironmentModule::HandleEvent(event_category_id_t category_id, event_id_t event_id, Foundation::EventDataInterface* data)
    {
        if(category_id == framework_event_category_)
        {
            HandleFrameworkEvent(event_id, data);
        }
        else if(category_id == resource_event_category_)
        {
            HandleResouceEvent(event_id, data);
        }
        else if(category_id == network_in_event_category_)
        {
            HandleNetworkEvent(event_id, data);
        }
        else if (category_id == network_state_event_category_)
        {
            if (event_id == ProtocolUtilities::Events::EVENT_SERVER_CONNECTED)
            {
                if (GetFramework()->GetDefaultWorldScene().get())
                {
                    CreateEnvironment();
                    CreateTerrain();
                    CreateWater();
                    //CreateEnvironment();
                    CreateSky();
                }
            }

            if (event_id == ProtocolUtilities::Events::EVENT_SERVER_DISCONNECTED)
            {
                if(postprocess_dialog_)
                    postprocess_dialog_->DisableAllEffects();
                ReleaseTerrain();
                ReleaseWater();
                ReleaseEnvironment();
                ReleaseSky();
                firstTime_ = true;
               
            }
        }
        else if(category_id == input_event_category_)
        {
            HandleInputEvent(event_id, data);
        }
        return false;
    }
Пример #4
0
int main(int argc, char** argv)
{
	{
	::SetPriorityClass(::GetCurrentProcess(),REALTIME_PRIORITY_CLASS);
	/*btDbvt::benchmark();
	exit(0);*/
	}
	// Initialize AntTweakBar
	// (note that AntTweakBar could also be intialize after GLUT, no matter)
	if(!TwInit(TW_OPENGL, NULL))
	{
		// A fatal error occured	
		fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
	}

	// Initialize Glut
	glutInit(&argc, argv);
	glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	int mainHandle = glutCreateWindow("CD Test Framework");

/*	HWND hWnd;
	hWnd = FindWindow("GLUT", "CD Test Framework");
	RECT Rect;
	GetWindowRect(hWnd, &Rect);
*/
	glutCreateMenu(NULL);
	glutSetWindow(mainHandle);
	glutDisplayFunc(RenderCallback);
	glutReshapeFunc(ReshapeCallback);
	glutIdleFunc(IdleCallback);
	glutKeyboardFunc(KeyboardCallback);
	glutSpecialFunc(ArrowKeyCallback);
	glutMouseFunc(MouseCallback);
	glutMotionFunc(MotionCallback);
	atexit(Terminate);	// Called after glutMainLoop ends

	glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	TwGLUTModifiersFunc(glutGetModifiers);

	// Setup default render states
	glClearColor(0.3f, 0.4f, 0.5f, 1.0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_CULL_FACE);
	glDepthFunc(GL_LEQUAL);

	// Setup lighting
	glEnable(GL_LIGHTING);
	float AmbientColor[] = { 0.0f, 0.1f, 0.2f, 0.0f };		glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientColor);
	float DiffuseColor[] = { 1.0f, 1.0f, 1.0f, 0.0f };		glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseColor);
	float SpecularColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };		glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularColor);
	float Position[] = { -10.0f, 1000.0f, -4.0f, 1.0f };	glLightfv(GL_LIGHT0, GL_POSITION, Position);
	glEnable(GL_LIGHT0);

	gFnt.init();
	gFnt.setScreenResolution(WINDOW_WIDTH, WINDOW_HEIGHT);
	gFnt.setColor(1.0f, 1.0f, 1.0f, 1.0f);

	CreateTerrain();

	// Create main tweak bar
	{
		gMainBar = TwNewBar("CollisionTests");
		TwEnumVal testEV[MAX_NB_TESTS] = {
//			{TEST_SPHERE_MESH_QUERY, "Sphere-mesh query"},
//			{TEST_OBB_MESH_QUERY, "OBB-mesh query"},
//			{TEST_CAPSULE_MESH_QUERY, "Capsule-mesh query"},
//			{TEST_COMPLETE_BOX_PRUNING, "OPCODE SAP 1024"},
			{TEST_COMPLETE_BOX_PRUNING_8192, "OPCODE BOX PRUNING 8192"},
//			{TEST_BULLET_SAP_1024, "Bullet SAP HASHPAIR 1024"},
//			{TEST_BULLET_SAP_8192, "Bullet SAP HASHPAIR 8192"},
//			{TEST_BULLET_SAP_SORTEDPAIRS_8192, "Bullet SAP SORTEDPAIR 8192"},
//			{TEST_BULLET_MULTISAP_8192, "Bullet MultiSAP 8192"},
//			{TEST_BIPARTITE_BOX_PRUNING, "Bipartite box pruning"},
			{TEST_DBVT_8192, "Bullet DBVT 8192"},
			{TEST_BULLET_CUDA_8192, "Bullet CUDA 8192"},
			{TEST_BULLET_3DGRID_8192, "Bullet 3D Grid 8192"},
			{TEST_OPCODE_ARRAY_SAP, "OPCODE ARRAY SAP"},
		};
		TwType testType = TwDefineEnum("CollisionTest", testEV, MAX_NB_TESTS);
		TwAddVarRW(gMainBar, "CollisionTests", testType, &gSelectedTest, "");		
		TwAddVarRW(gMainBar, "% of updates",TW_TYPE_INT32,&percentUpdate,"min=0 max=100");
		TwAddVarRW(gMainBar, "Draw",TW_TYPE_BOOLCPP,&enableDraw,"");
	}

	// Create tests
	gTest = 0;
//	gCollisionTests[TEST_SPHERE_MESH_QUERY]	= new SphereMeshQuery;
//	gCollisionTests[TEST_OBB_MESH_QUERY]	= new OBBMeshQuery;
//	gCollisionTests[TEST_CAPSULE_MESH_QUERY]	= new CapsuleMeshQuery;
//	gCollisionTests[TEST_COMPLETE_BOX_PRUNING]	= new CompleteBoxPruningTest(NUM_SAP_BOXES);
 //	gCollisionTests[TEST_COMPLETE_BOX_PRUNING_8192]	= new CompleteBoxPruningTest(NUM_SAP_BOXES);
	gCollisionTests[TEST_COMPLETE_BOX_PRUNING_8192]	= new CompleteBoxPruningTest(NUM_SAP_BOXES);
//	gCollisionTests[TEST_BULLET_SAP_1024]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,1);
// 	gCollisionTests[TEST_BULLET_SAP_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,1);
//	gCollisionTests[TEST_BULLET_SAP_SORTEDPAIRS_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,3);
// 	gCollisionTests[TEST_BULLET_MULTISAP_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,6);
//	gCollisionTests[TEST_BIPARTITE_BOX_PRUNING]	= new BipartiteBoxPruningTest;
	gCollisionTests[TEST_DBVT_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,7);
	gCollisionTests[TEST_BULLET_CUDA_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,8);
	gCollisionTests[TEST_BULLET_3DGRID_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,9);
	gCollisionTests[TEST_OPCODE_ARRAY_SAP]	= new OpcodeArraySAPTest(NUM_SAP_BOXES);

	for(int i=0;i<MAX_NB_TESTS;i++)
		gCollisionTests[i]->Init();
	gCollisionTests[gTest]->Select();

	//
	MotionCallback(0,0);

	// Run
	glutMainLoop();

	return 0;
}
Пример #5
0
//----------------------------------------------------------------------------
void Castle::CreateScene ()
{
    mScene = new0 Node();
    mTrnNode = new0 Node();
    mScene->AttachChild(mTrnNode);
    mWireState = new0 WireState();
    mRenderer->SetOverrideWireState(mWireState);

    CreateLights();
    CreateEffects();
    CreateTextures();
    CreateSharedMeshes();

    CreateWallTurret02();
    CreateWallTurret01();
    CreateWall02();
    CreateWall01();
    CreateQuadPatch01();
    CreateMainGate01();
    CreateMainGate();
    CreateExterior();
    CreateFrontHall();
    CreateFrontRamp();
    CreateDrawBridge();
    CreateCylinder02();
    CreateBridge();
    CreateLargePort();
    CreateSmallPort(1);
    CreateSmallPort(2);
    CreateRope(1);
    CreateRope(2);

    int i;
    for (i = 1; i <= 7; ++i)
    {
        CreateWoodShield(i);
    }
    for (i = 1; i <= 17; ++i)
    {
        CreateTorch(i);
    }
    for (i = 1; i <= 3; ++i)
    {
        CreateKeg(i);
    }
    for (i = 2; i <= 37; ++i)
    {
        CreateBarrel(i);
    }
    for (i = 1; i <= 48; ++i)
    {
        CreateDoorFrame(i);
    }
    for (i = 49; i <= 60; ++i)
    {
        CreateDoorFramePivotTrn(i);
    }
    CreateDoorFrame(61);
    CreateDoorFrameScalePivotTrn(62);
    CreateDoorFrameScalePivotTrn(63);
    for (i = 64; i <= 68; ++i)
    {
        CreateDoorFrame(i);
    }
    for (i = 69; i <= 78; ++i)
    {
        CreateDoorFramePivotTrn(i);
    }
    CreateDoorFrame(79);
    CreateDoorFrameScalePivotTrn(80);
    CreateDoorFrameScalePivotTrn(81);
    CreateDoorFramePivotTrn(82);
    CreateDoorFramePivotTrn(83);
    CreateDoorFramePivotTrn(73);

    CreateBunk(1);
    for (i = 4; i <= 20; ++i)
    {
        CreateBunk(i);
    }
    for (i = 1; i <= 36; ++i)
    {
        CreateBench(i);
    }
    for (i = 1; i <= 9; ++i)
    {
        CreateTable(i);
    }
    for (i = 1; i <= 4; ++i)
    {
        CreateBarrelRack(i);
    }
    for (i = 1; i <= 36; ++i)
    {
        CreateChest(i);
    }
    for (i = 1; i <= 3; ++i)
    {
        CreateCeilingLight(i);
    }
    for (i = 1; i <= 7; ++i)
    {
        CreateSquareTable(i);
    }
    for (i = 1; i <= 27; ++i)
    {
        CreateSimpleChair(i);
    }
    for (i = 1; i <= 42; ++i)
    {
        CreateMug(i);
    }
    for (i = 1; i <= 9; ++i)
    {
        CreateDoor(i);
    } 

    CreateTerrain();
    CreateSkyDome();
    CreateWater();
    CreateWater2();
}