コード例 #1
0
ファイル: PhysicsScene.cpp プロジェクト: Tetriste/LudumDare29
		PhysicsScene::PhysicsScene(const int & nbThreads, const physx::PxReal & stepSize, physx::PxFoundation * foundation, physx::PxProfileZoneManager * profileZoneManager, physx::PxPhysics * physics, physx::PxCooking * cooking)
		{
			m_nbThreads = nbThreads;
			m_accumulator = 0.0f;
			m_stepSize = stepSize;

			m_foundation = foundation;
			m_profileZoneManager = profileZoneManager;
			m_physics = physics;
			m_cooking = cooking;

			physx::PxSceneDesc sceneDesc(m_physics->getTolerancesScale());
			sceneDesc.gravity = physx::PxVec3(0.0f, -9.81f, 0.0f);
			//customizeSceneDesc(sceneDesc);

			if(!sceneDesc.cpuDispatcher)
			{
				m_cpuDispatcher = physx::PxDefaultCpuDispatcherCreate(m_nbThreads);

				ATUM_ASSERT_MESSAGE(m_cpuDispatcher, "PxDefaultCpuDispatcherCreate failed!");

				sceneDesc.cpuDispatcher = m_cpuDispatcher;
			}

			if(!sceneDesc.filterShader)
			{
				sceneDesc.filterShader = physx::PxDefaultSimulationFilterShader;
			}

			m_scene = m_physics->createScene(sceneDesc);

			ATUM_ASSERT_MESSAGE(m_scene, "createScene failed!");
		}
コード例 #2
0
ファイル: PhysicsUtil.cpp プロジェクト: caomw/osgPhysX
PxScene* createScene( const osg::Vec3& gravity, const PxSimulationFilterShader& filter,
                      physx::PxSceneFlags flags, unsigned int numThreads, bool useGPU )
{
    PxSceneDesc sceneDesc( SDK_OBJ->getTolerancesScale() );
    sceneDesc.gravity = PxVec3(gravity[0], gravity[1], gravity[2]);
    sceneDesc.filterShader = filter;
    sceneDesc.flags |= flags;

#if USE_PHYSX_33
    if ( useGPU )
    {
        PxCudaContextManager* cudaManager = Engine::instance()->getOrCreateCudaContextManager();
        if ( cudaManager ) sceneDesc.gpuDispatcher = cudaManager->getGpuDispatcher();
    }
#endif

    if ( !sceneDesc.gpuDispatcher && !sceneDesc.cpuDispatcher )
    {
        PxDefaultCpuDispatcher* defCpuDispatcher = PxDefaultCpuDispatcherCreate(numThreads);
        if ( !defCpuDispatcher )
           OSG_WARN << "Failed to create default Cpu dispatcher." << std::endl;
        sceneDesc.cpuDispatcher = defCpuDispatcher;
    }
    
    PxScene* scene = SDK_OBJ->createScene( sceneDesc );
    if ( !scene )
    {
        OSG_WARN << "Failed to create the physics world." << std::endl;
        return NULL;
    }
    scene->setVisualizationParameter( PxVisualizationParameter::eSCALE, 1.0f );
    scene->setVisualizationParameter( PxVisualizationParameter::eCOLLISION_SHAPES, 1.0f );
    return scene;
}
コード例 #3
0
bool PhysXPhysics::VInitialize()
{
	VLoadPhysicsConfigXml();
	int version = PX_PHYSICS_VERSION;
	m_pFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, m_allocatorCallback, m_errorCallback);
	m_pPhysicsSdk = PxCreatePhysics(PX_PHYSICS_VERSION, *m_pFoundation, PxTolerancesScale(), true);

	if (!m_pPhysicsSdk)
	{
		BE_ERROR("Error Creating PhysX device.");
		return false;
	}

	PxSceneDesc sceneDesc(m_pPhysicsSdk->getTolerancesScale());

	sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f); //Set Gravity
	m_pDispatcher = PxDefaultCpuDispatcherCreate(2);
	sceneDesc.cpuDispatcher = m_pDispatcher;
	sceneDesc.filterShader = PxDefaultSimulationFilterShader;

	m_pScene = m_pPhysicsSdk->createScene(sceneDesc);

#ifdef ENABLE_PHYSX_PVD
	ConnectPVD();
#endif
	
	return true;
}
コード例 #4
0
ファイル: apex.cpp プロジェクト: schulchr/Olympus
bool Apex::CreateScene()
{
	PxSceneDesc sceneDesc(mPhysics->getTolerancesScale());
    sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);

    if(!sceneDesc.cpuDispatcher)
    {
        mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
        if(!mCpuDispatcher)
            return false;
        sceneDesc.cpuDispatcher    = mCpuDispatcher;
    }

    if(!sceneDesc.filterShader)
    {
        sceneDesc.filterShader = PxDefaultSimulationFilterShader;
    }
    
    /*#ifdef PX_WINDOWS
    if(!sceneDesc.gpuDispatcher && mCudaContextManager)
    {
        sceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();
    }
    #*/
    mProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mFoundation);
    pxtask::CudaContextManagerDesc cudaContextManagerDesc;
    mCudaContextManager = pxtask::createCudaContextManager(*mFoundation,cudaContextManagerDesc, mProfileZoneManager);
    sceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();


	mScene.push_back(mPhysics->createScene(sceneDesc));

    if (!mScene[mCurrentScene])
        return false;


	 NxApexSceneDesc apexSceneDesc;
    // Create the APEX scene...
    
    apexSceneDesc.scene = mScene[mCurrentScene];
	
    if(apexSceneDesc.isValid())
		gApexScene.push_back(gApexSDK->createScene(apexSceneDesc));
    else
        return false;

    if(!gApexScene[mCurrentScene])
        return false;

	gApexScene[mCurrentScene]->setLODResourceBudget(10000.f);

	static const physx::PxU32 viewIDlookAtRightHand = gApexScene[mCurrentScene]->allocViewMatrix(physx::apex::ViewMatrixType::LOOK_AT_LH);
	static const physx::PxU32 projIDperspectiveCubicRightHand = gApexScene[mCurrentScene]->allocProjMatrix(physx::apex::ProjMatrixType::USER_CUSTOMIZED);

	gApexScene[mCurrentScene]->setUseViewProjMatrix(viewIDlookAtRightHand, projIDperspectiveCubicRightHand);
}
コード例 #5
0
ファイル: PhysXDevice.cpp プロジェクト: SeungMinChoi/Jaraffe
void JF::JFCPhysXDevice::SceneSetting(PxVec3 _gravity, PxReal _staticFriction, PxReal _dynamicFriction, PxReal _restitution)
{
	// 1) Scene 생성
	PxSceneDesc sceneDesc(m_Physics->getTolerancesScale());
	sceneDesc.gravity		= _gravity;
	sceneDesc.cpuDispatcher = m_Dispatcher;
	sceneDesc.filterShader	= PxDefaultSimulationFilterShader;
	
	m_pScene = m_Physics->createScene(sceneDesc);

	// 2) 마찰력 정보 생성
	m_Material = m_Physics->createMaterial(_staticFriction, _dynamicFriction, _restitution);
}
コード例 #6
0
ファイル: Physics.cpp プロジェクト: RoyKirk/AIEWork
void Physics::SetUpPhysX()
{
	PxAllocatorCallback *myCallback = new myAllocator();
	g_PhysicsFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, *myCallback, gDefaultErrorCallback);
	g_Physics = PxCreatePhysics(PX_PHYSICS_VERSION, *g_PhysicsFoundation, PxTolerancesScale());
	PxInitExtensions(*g_Physics);
	//create physics material
	g_PhysicsMaterial = g_Physics->createMaterial(0.5f, 0.5f, 0.5f);
	PxSceneDesc sceneDesc(g_Physics->getTolerancesScale());
	sceneDesc.gravity = PxVec3(0, -10.0f, 0);
	sceneDesc.filterShader = &physx::PxDefaultSimulationFilterShader;
	sceneDesc.cpuDispatcher = PxDefaultCpuDispatcherCreate(1);
	g_PhysicsScene = g_Physics->createScene(sceneDesc);
}
コード例 #7
0
ファイル: px3World.cpp プロジェクト: elfprince13/Torque3D
bool Px3World::initWorld( bool isServer, ProcessList *processList )
{
   if ( !gPhysics3SDK )
   {
      Con::errorf( "Physx3World::init - PhysXSDK not initialized!" );
      return false;
   }

   mIsServer = isServer;
   
   physx::PxSceneDesc sceneDesc(gPhysics3SDK->getTolerancesScale());

   sceneDesc.gravity = px3Cast<physx::PxVec3>(mGravity);
   sceneDesc.userData = this;
   if(!sceneDesc.cpuDispatcher)
   {
      //Create shared cpu dispatcher
      if(!smCpuDispatcher)
         smCpuDispatcher = physx::PxDefaultCpuDispatcherCreate(PHYSICSMGR->getThreadCount());
 
      sceneDesc.cpuDispatcher = smCpuDispatcher;
      Con::printf("PhysX3 using Cpu: %d workers", smCpuDispatcher->getWorkerCount());
   }
   
   sceneDesc.flags |= physx::PxSceneFlag::eENABLE_CCD;
   sceneDesc.flags |= physx::PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
   sceneDesc.filterShader  = physx::PxDefaultSimulationFilterShader;

   mScene = gPhysics3SDK->createScene(sceneDesc);
   //cache renderbuffer for use with debug drawing
   mRenderBuffer = const_cast<physx::PxRenderBuffer*>(&mScene->getRenderBuffer());

   physx::PxDominanceGroupPair debrisDominance( 0.0f, 1.0f );
   mScene->setDominanceGroupPair(0,31,debrisDominance);

   mControllerManager = PxCreateControllerManager(*mScene);

   AssertFatal( processList, "Px3World::init() - We need a process list to create the world!" );
   mProcessList = processList;
   mProcessList->preTickSignal().notify( this, &Px3World::getPhysicsResults );
   mProcessList->postTickSignal().notify( this, &Px3World::tickPhysics, 1000.0f );

   return true;
}
コード例 #8
0
void initializePhysx()
{
	// Init Physx
	physx::PxFoundation* foundation = PxCreateFoundation( PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback );
	if( !foundation )
		std::cerr << "PxCreateFoundation failed!" << std::endl;

	gPhysicsSDK = PxCreatePhysics( PX_PHYSICS_VERSION, *foundation, physx::PxTolerancesScale() );
	if( gPhysicsSDK == NULL )
	{
		std::cerr << "Error creating PhysX3 device." << std::endl;
		std::cerr << "Exiting.." << std::endl;
		exit(1);
	}

	if( !PxInitExtensions( *gPhysicsSDK ))
		std::cerr << "PxInitExtensions failed!" << std::endl;

	// Create Scene
	physx::PxSceneDesc sceneDesc( gPhysicsSDK->getTolerancesScale() );
	sceneDesc.gravity = physx::PxVec3( 0.0f, gravity, 0.0f );

	if( !sceneDesc.cpuDispatcher )
	{
        physx::PxDefaultCpuDispatcher* mCpuDispatcher = physx::PxDefaultCpuDispatcherCreate(1);

        if( !mCpuDispatcher )
           std::cerr << "PxDefaultCpuDispatcherCreate failed!" << std::endl;

        sceneDesc.cpuDispatcher = mCpuDispatcher;
    } 
 	if( !sceneDesc.filterShader )
		sceneDesc.filterShader  = gDefaultFilterShader;

	gScene = gPhysicsSDK->createScene(sceneDesc);
	if( !gScene )
        std::cerr << "createScene failed!" << std::endl;

	gScene->setVisualizationParameter(physx::PxVisualizationParameter::eSCALE, 1.0);
	gScene->setVisualizationParameter(physx::PxVisualizationParameter::eCOLLISION_SHAPES, 1.0f);

	// Create Actors
	createActors();
}
コード例 #9
0
// Set up PhysX
void InitializePhysX() {
	gFoundation = PxCreateFoundation(PX_FOUNDATION_VERSION, gAllocator, gErrorCallback);

	gPvd = PxCreatePvd(*gFoundation);
	PxPvdTransport* transport = PxDefaultPvdSocketTransportCreate("127.0.0.1", 5425, 10);
	gPvd->connect(*transport, PxPvdInstrumentationFlag::eALL);

	gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(), true, gPvd);

	PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
	sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
	gDispatcher = PxDefaultCpuDispatcherCreate(2);
	sceneDesc.cpuDispatcher = gDispatcher;
	sceneDesc.filterShader = contactReportFilterShader/*PxDefaultSimulationFilterShader*/;
	sceneDesc.simulationEventCallback = &gContactReportCallback;	// contact callback
	sceneDesc.contactModifyCallback = &gModContactReportCallback;	// modification contact callback
	gScene = gPhysics->createScene(sceneDesc);

	PxPvdSceneClient* pvdClient = gScene->getScenePvdClient();
	if (pvdClient)
	{
		pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_CONSTRAINTS, true);
		pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_CONTACTS, true);
		pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_SCENEQUERIES, true);
	}
	gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f);

	// add some physics objects
	AddPhyObjects();

	createChain(PxTransform(PxVec3(10.0f, 30.0f, -30.0f)), 5, PxBoxGeometry(2.0f, 0.5f, 0.5f), 4.0f, createLimitedSpherical);
	createChain(PxTransform(PxVec3(0.0f, 30.0f, -30.0f)), 5, PxBoxGeometry(2.0f, 0.5f, 0.5f), 4.0f, createBreakableFixed);
	createChain(PxTransform(PxVec3(-10.0f, 30.0f, -30.0f)), 5, PxBoxGeometry(2.0f, 0.5f, 0.5f), 4.0f, createDampedD6);

	gScene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1.0f);
	gScene->setVisualizationParameter(PxVisualizationParameter::eACTOR_AXES, 1.0f);
	gScene->setVisualizationParameter(PxVisualizationParameter::eCOLLISION_SHAPES, 2.0f);
	gScene->setVisualizationParameter(PxVisualizationParameter::eCONTACT_NORMAL, 2.0f);


}
コード例 #10
0
ファイル: kzsPhysXFramework.cpp プロジェクト: kzs-sgw/GLSL
// **initPx_CreateScene**
void kzsPhysXFramework::initPx_CreateScene( PxVec3 _gravity )
{
	printf( "creating the scene\n" );
	// create the scene
	PxSceneDesc sceneDesc( gPhysicsSDK->getTolerancesScale() );
	sceneDesc.gravity = _gravity;

	if ( !sceneDesc.cpuDispatcher )
	{
		PxDefaultCpuDispatcher* mCpuDispatcher = PxDefaultCpuDispatcherCreate(1);
		sceneDesc.cpuDispatcher = mCpuDispatcher;
	}
	
	if ( !sceneDesc.filterShader )
	{
		sceneDesc.filterShader = gDefaultFilterShader;
	}
	
	gScene = gPhysicsSDK->createScene( sceneDesc );
	if ( !gScene ) cerr << "createScene failed!" << endl;
}
コード例 #11
0
		/**
		 * Private method which is used to initialize engine physics scene. Create scene based on scene descriptor,
		 * set gravity, inner obejcts like cpu dispatcher, filter shader and simulation event callback object.
		 */
		void PhysicsManager::initializeScene()
		{
			PxSceneDesc sceneDesc(physicsSDK->getTolerancesScale());
			sceneDesc.gravity = PxVec3(0.0f, -9.8f, 0.0f);
			if(!sceneDesc.cpuDispatcher)
			{
				PxDefaultCpuDispatcher* cpuDispatcher = PxDefaultCpuDispatcherCreate(1);
				if(!cpuDispatcher)
					Logger::getInstance()->saveLog(Log<string>("PxDefaultCpuDispatcherCreate creation error occurred!"));		
				sceneDesc.cpuDispatcher = cpuDispatcher;
			}

			if(!sceneDesc.filterShader)
				sceneDesc.filterShader = defaultFilterShader;

			scene = physicsSDK->createScene(sceneDesc);
		
			if(!scene)
				Logger::getInstance()->saveLog(Log<string>("Scene creation error occurred!"));
			
			scene->setVisualizationParameter(PxVisualizationParameter::eSCALE,1.0);
			scene->setVisualizationParameter(PxVisualizationParameter::eCOLLISION_SHAPES,1.0f);
			scene->setSimulationEventCallback(collisionHandler);
		}
コード例 #12
0
ファイル: EnginePhysics.cpp プロジェクト: thomhughes/Awe
void InitializePhysX(vector<PhysXObject*>* &cubeList)
{
    allActors = new vector<PhysXObject*>;

    PxFoundation* foundation = PxCreateFoundation(PX_PHYSICS_VERSION,
                               gDefaultAllocatorCallback, gDefaultErrorCallback);
    gPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *foundation, PxTolerancesScale());

    if(gPhysicsSDK == NULL)
    {
        exit(1);
    }

    PxInitExtensions(*gPhysicsSDK);

    PxSceneDesc sceneDesc(gPhysicsSDK->getTolerancesScale());

    sceneDesc.gravity=PxVec3(0.0f, -9.8f, 0.0f);

    if(!sceneDesc.cpuDispatcher)
    {
        PxDefaultCpuDispatcher* mCpuDispatcher = PxDefaultCpuDispatcherCreate(3);

        sceneDesc.cpuDispatcher = mCpuDispatcher;
    }

    if(!sceneDesc.filterShader)
        sceneDesc.filterShader = gDefaultFilterShader;

    gScene = gPhysicsSDK->createScene(sceneDesc);

    gScene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1.0);
    gScene->setVisualizationParameter(PxVisualizationParameter::eCOLLISION_SHAPES, 1.0f);


    //1) Create Planes
    PxMaterial* mMaterial = gPhysicsSDK->createMaterial(0.5, 0.5, 0.5);

    for(int i = 0; i < 1; i++)
    {
        PhysXObject* plane = new PhysXObject;
        plane->actor = gPhysicsSDK->createRigidStatic(planePoses[i]);

        PxShape* shape = plane->actor->createShape(PxPlaneGeometry(), *mMaterial);

        gScene->addActor(*(plane->actor));
        allActors->push_back(plane);
        planes.push_back(plane);
    }

    //2) Create Planets
    PxReal planetDensity = 1.0f;
    PxVec3 planetDimensions(2,2,2);
    PxBoxGeometry planetGeom(planetDimensions);
    PxTransform planetTransform;

    for(int i = 0; i < PLANET_NUM; i++)
    {
        planetTransform = planetTransforms[i];
        PhysXObject* planet = new PhysXObject;
        planet->actor = PxCreateStatic(*gPhysicsSDK, planetTransform, planetGeom, *mMaterial);

        EnableGravity(planet->actor);

        gScene->addActor(*(planet->actor));
        allActors->push_back(planet);
        planets.push_back(planet);

        //HACK:
        /* Create the joint handlers for distance limiting
        /* We need to do this because a distance joint attached to an actor
        /* seems to void collisions between those two actors (i.e. "phases through")
        /* So we make another actor in the same position to hold the position

        PhysXObject* newHandle = new PhysXObject;
        newHandle->actor = PxCreateStatic(*gPhysicsSDK, tran, boxgeom, *mMaterial);

        gScene->addActor(*(newHandle->actor));
        planetJointHandles.push_back(newHandle);
        //We also don't need to worry about drawing the joints, for obvious reasons
        */
    }

    //3) Create Cubes
    PxReal density = 1.0f;
    PxTransform transform(PxVec3(0.0f, 0.0f, 0.0f), PxQuat::createIdentity());
    PxVec3 dimensions(0.5, 0.5, 0.5);
    PxBoxGeometry geometry(dimensions);

    for(int i = 0; i < BLOCK_NUM; i++)
    {
        srand((time(NULL) * i) + time(NULL));

        transform.p = PxVec3((float)((rand() % (2 * PLANET_HEIGHT)) - PLANET_HEIGHT),
                             (float)((rand() % (2 * PLANET_HEIGHT)) - PLANET_HEIGHT),
                             (float)((rand() % (2 * PLANET_HEIGHT)) - PLANET_HEIGHT));

        PhysXObject* cube = new PhysXObject;

        cube->actor = PxCreateDynamic(*gPhysicsSDK, transform, geometry, *mMaterial, density);

        //Create Distance Joints between planets here
        //Not included for run time optimizations
        //End creating distance joints

        //Create D6 Joints between planets here
        //Not included for run time optimizations
        //End creating distance joints

        cube->actor->isRigidDynamic()->setAngularDamping(0.75);
        cube->actor->isRigidDynamic()->setLinearVelocity(PxVec3(0,0,0));

        gScene->addActor(*(cube->actor));
        allActors->push_back(cube);
        boxes.push_back(cube);
    }

    cubeList = allActors;
}
コード例 #13
0
ファイル: gameWorld.cpp プロジェクト: abucraft/opengl-balls
void GameWorld::init()
{
	gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
	if (!gFoundation) {
		printf("PxCreateFoundation failed!");
	}
	gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(), true);
	if (!PxInitExtensions(*gPhysics)) {
		printf("init error pxinit\n");
	}
	gCooking = PxCreateCooking(PX_PHYSICS_VERSION, *gFoundation, PxCookingParams(gPhysics->getTolerancesScale()));
	if (!gCooking) {
		printf("PxCreateCooking failed!\n");
	}
	PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
	sceneDesc.gravity = PxVec3(0.0f, -98.0f, 0.0f);
	gDispatcher = PxDefaultCpuDispatcherCreate(2);
	sceneDesc.cpuDispatcher = gDispatcher;
	sceneDesc.filterShader = PxDefaultSimulationFilterShader;
	gScene = gPhysics->createScene(sceneDesc);
	gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f);
	PxRigidStatic* groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, 0, 1, 400), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, 0, -1, 400), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(1, 0, 0, 280), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(-1, 0, 0, 280), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, -1, 0, 600), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, 1, 0, -1), *gMaterial);
	gScene->addActor(*groundPlane);
	gGround.loadFromObj(GROUND_FILE);
	gGround.cookingMesh(*gPhysics, *gCooking);
	gGround.createActor(*gMaterial, *gPhysics);
	gScene->addActor(*(gGround.actor));

	//包围盒
	box.loadFromObj(BOX_FILE);

	//初始化飞球
	pxFlyBall = new PxFlyBall(Color4f(1.0, 200 / 255.0, 0), 5.0);
	Material mtl;
	PerlinImage perlinYellow = createPerlinLightYelloImage(40, 40, 6, 1.8);
	PerlinTexture(perlinYellow, mtl.kd_texid);
	mtl.ka = Color4f(1, 1, 1, 1);
	mtl.kd = Color4f(1, 1, 1, 1);
	mtl.ks = Color4f(1, 1, 1, 1);
	pxFlyBall->mtl = mtl;
	pxFlyBall->createPxBall(*gPhysics, PxTransform(PxVec3(rand() % 500 - 250, 100, rand() % 700 - 350)), *gMaterial);
	pxFlyBall->pxActor->setAngularDamping(0.5);
	perlinYellow.clear();
	gScene->addActor(*(pxFlyBall->pxActor));

	//初始化白球
	pxControlBall = new PxControlBall(Color4f(1.0, 1.0, 1.0), 5.0);
	PerlinImage perlinGray = createPerlinGrayImage(40, 40, 6, 1.8);
	PerlinTexture(perlinGray, mtl.kd_texid);
	mtl.ka = Color4f(1, 1, 1, 1);
	mtl.kd = Color4f(1, 1, 1, 1);
	mtl.ks = Color4f(0, 0, 0, 0);
	pxControlBall->mtl = mtl;
	pxControlBall->createPxBall(*gPhysics, PxTransform(PxVec3(0, 50, 0)), *gMaterial);
	pxControlBall->pxActor->setAngularDamping(0.5);
	perlinGray.clear();
	gScene->addActor(*(pxControlBall->pxActor));
	
	GLfloat light1PosType[] = { -5.0,1.0,5.0,0.0 };
	GLfloat whiteColor[] = { 1.0,1.0,1.0,1.0 };
	GLfloat darkColor[] = { 0.4,0.4,0.4,1 };
	GLfloat specColor[] = { 1,1,1,1 };
	GLfloat lightColor[] = { 1,1,1,1 };
	GLfloat globalAmbient[] = { 0.2,0.2,0.2,1.0 };
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbient);
	glLightfv(GL_LIGHT1, GL_AMBIENT, darkColor);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor);
	glLightfv(GL_LIGHT1, GL_SPECULAR, specColor);
	glLightfv(GL_LIGHT1, GL_POSITION, light1PosType);
}
コード例 #14
0
	void Main::initScene()
	{
		Ogre::LogManager::getSingleton().logMessage("Main initScene");

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::UPDATE_PER_FRAME);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::RENDERING_BEGIN);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::PHYSICS_BEGIN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::PHYSICS_SUBSTEP);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::PHYSICS_END);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::UPDATE_INDEPENDANT);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::KEY_DOWN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::KEY_UP);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::MOUSE_DOWN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::MOUSE_UP);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::MOUSE_MOVE);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::GAMESTATE_ENTER);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::GAMESTATE_LEAVE);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::CONSOLE_INGAME);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::LOADLEVEL_BEGIN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::LOADLEVEL_END);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::SAVELEVEL_BEGIN);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::SAVELEVEL_END);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::ACTOR_ONSLEEP);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::ACTOR_ONWAKE);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::MATERIAL_ONCONTACT);

		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::REPARSE_SCRIPTS_PRE);
		Ice::MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::REPARSE_SCRIPTS_POST);

		MessageSystem::Instance().CreateNewsgroup(GlobalMessageIDs::ENABLE_GAME_CLOCK);

		Ogre::LogManager::getSingleton().logMessage("Starting PhysX");

		//Start up OgrePhysX
		OgrePhysX::World::getSingleton().init();

		mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Esgaroth");
		mCamera = mSceneMgr->createCamera("MainCamera");
		mCamera->lookAt(Ogre::Vector3(0,0,1));
		mCamera->setNearClipDistance(0.4f);
		mCamera->setFarClipDistance(50000);

		mViewport = mWindow->addViewport(mCamera);
		mViewport->setBackgroundColour(Ogre::ColourValue::Black);
		mCamera->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight()));

		//Create PhysX Scene
		PxSceneDesc sceneDesc(OgrePhysX::getPxPhysics()->getTolerancesScale());
		sceneDesc.gravity = PxVec3(0, -9.81f, 0);
		sceneDesc.filterShader = &PhysXSimulationFilterShader;
		mPhysXSimulationCallback = ICE_NEW PhysXSimulationEventCallback();
		sceneDesc.simulationEventCallback = mPhysXSimulationCallback;
		mPhysXScene = OgrePhysX::World::getSingleton().addScene("Main", mSceneMgr, sceneDesc);

		mPreviewSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Esgaroth_Preview");

		InitOgreResources();

		Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
		Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC);
		Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(8); 

		Ogre::MaterialManager::getSingleton().addListener(new DepthSchemeHandler(), "depth");

		//mPreviewSceneMgr->setSkyBox(true, "Sky/ClubTropicana", 2000);
		mPreviewSceneMgr->setAmbientLight(Ogre::ColourValue(0.8f, 0.8f, 0.8f));
		Ogre::Light *ambientlight = mPreviewSceneMgr->createLight("SkyLight");
		ambientlight->setType(Ogre::Light::LightTypes::LT_DIRECTIONAL);
		ambientlight->setDirection(Ogre::Vector3(0,-1,0.4f).normalisedCopy());
		ambientlight->setDiffuseColour(Ogre::ColourValue(1,1,1));
		ambientlight->setSpecularColour(Ogre::ColourValue(1,1,1));

		mSceneMgr->setAmbientLight(Ogre::ColourValue(0.3f,0.2f,0.2f));
		//mSceneMgr->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue::Blue, 0.015);

		mCameraController = ICE_NEW FreeFlightCameraController();
		SceneManager::Instance().AcquireCamera(mCameraController);

		//init scripting stuff
		ScriptSystem::GetInstance();
		LuaScript::SetLoader(OgreFileLoader);
		LuaScript::SetLogFn(ScriptLogFn);
		/*	GUISystem::GetInstance();
		MusicSystem::GetInstance();
		ScriptedControls::GetInstance();*/

		//sound
		mSoundManager = OgreOggSound::OgreOggSoundManager::getSingletonPtr();
		mSoundManager->init("");
		mSoundManager->setSceneManager(mSceneMgr);
		mSoundManager->setDistanceModel(AL_LINEAR_DISTANCE);
		//mCamera->getParentSceneNode()->attachObject(mSoundManager->getListener());

		InitCompositor();

		Ogre::MovableObject::setDefaultVisibilityFlags( Ice::VisibilityFlags::V_DEFAULT);

		/*mCollisionCallback = ICE_NEW ScriptedCollisionCallback();
		NxOgre::ActorGroup *dynamicbodies = mScene->createActorGroup("DynamicBody");
		mScene->addMaterialPair(
		dynamicbodies->((NxOgre::GroupCallback::InheritedCallback*)(mCollisionCallback));
		dynamicbodies->setCollisionCallback(dynamicbodies, NX_NOTIFY_ALL, false);*/

		mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);

		mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3);
		mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_SPOTLIGHT, 1);
		mSceneMgr->setShadowTextureCount(3);
		mSceneMgr->setShadowTextureConfig(0, 2048, 2048, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(1, 2048, 2048, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(2, 2048, 2048, Ogre::PF_FLOAT32_R);
		/*mSceneMgr->setShadowTextureConfig(3, 1024, 1024, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(4, 1024, 1024, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(5, 1024, 1024, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(6, 1024, 1024, Ogre::PF_FLOAT32_R);
		mSceneMgr->setShadowTextureConfig(7, 1024, 1024, Ogre::PF_FLOAT32_R);*/
		/*mSceneMgr->setShadowTextureSelfShadow(true);*/
		mSceneMgr->setShadowTextureCasterMaterial("shadow_caster");

		mSceneMgr->getShadowTexture(0)->getBuffer()->getRenderTarget()->getViewport(0)->setBackgroundColour(Ogre::ColourValue::White);
		mSceneMgr->getShadowTexture(0)->getBuffer()->getRenderTarget()->getViewport(0)->setClearEveryFrame(true);
		mSceneMgr->getShadowTexture(1)->getBuffer()->getRenderTarget()->getViewport(0)->setBackgroundColour(Ogre::ColourValue::White);
		mSceneMgr->getShadowTexture(1)->getBuffer()->getRenderTarget()->getViewport(0)->setClearEveryFrame(true);
		mSceneMgr->getShadowTexture(2)->getBuffer()->getRenderTarget()->getViewport(0)->setBackgroundColour(Ogre::ColourValue::White);
		mSceneMgr->getShadowTexture(2)->getBuffer()->getRenderTarget()->getViewport(0)->setClearEveryFrame(true);

		mSceneMgr->setShadowCasterRenderBackFaces(false);

		// shadow camera setup
		Ogre::FocusedShadowCameraSetup* spotSetup = ICE_NEW Ogre::FocusedShadowCameraSetup();
		mSpotShadowCameraSetup = Ogre::ShadowCameraSetupPtr(spotSetup);

		Ogre::PSSMShadowCameraSetup* pssmSetup = ICE_NEW Ogre::PSSMShadowCameraSetup();
		pssmSetup->calculateSplitPoints(3, 0.4f, 300, 0.95f);
		pssmSetup->setSplitPadding(1);
		pssmSetup->setOptimalAdjustFactor(0, 2);
		pssmSetup->setOptimalAdjustFactor(1, 0.6f);
		pssmSetup->setOptimalAdjustFactor(2, 0.3f);//0.4f);//2, 0.5);
		mDirectionalShadowCameraSetup = Ogre::ShadowCameraSetupPtr(pssmSetup);
		mSceneMgr->setShadowCameraSetup(mDirectionalShadowCameraSetup);
		const Ogre::PSSMShadowCameraSetup::SplitPointList& splitPointList = pssmSetup->getSplitPoints();
		Ogre::Vector4 PSSMSplitPoints;
		for (int i = 0; i < 3; ++i)
		{
			PSSMSplitPoints[i] = splitPointList[i];
		}

		IceNote("PSSMSplitPoints: " + Ogre::StringConverter::toString(PSSMSplitPoints));

		SceneManager::Instance().Init();

		//Load save initialisation
		RegisterStandardAtoms();
		LoadSave::LoadSave::Instance().SetLogFunction(LogMessage);

		LoadSave::LoadSave::Instance().RegisterObject(&DataMap::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&DataMap::Item::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&GenericProperty::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&GameObject::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&ObjectReference::Register);
		LoadSave::LoadSave::Instance().RegisterObject(&LoadSave::SaveableDummy::Register);

		LoadSave::LoadSave::Instance().RegisterObject(&NavigationMesh::Register);

		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<GameObject>("vector<GameObjectPtr>"));
		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<ObjectReference>("vector<ObjectReferencePtr>"));
		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<GOComponent>("vector<GOComponentPtr>"));
		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<NavigationMesh::PathNodeTree>("vector<PathNodeTreePtr>"));
		LoadSave::LoadSave::Instance().RegisterAtom((LoadSave::AtomHandler*)new SaveableVectorHandler<DataMap::Item>("vector<DataMapItemPtr>"));

		//Init script functions
		InitCoreLuaFunctions();

		//Load Plugins
		LoadPlugins();
		//initialize scripts
		ScriptSystem::GetInstance().CreateInstance("StartEngine.lua");
		ScriptSystem::GetInstance().CreateInstance("InitEngine.lua");

		MaterialTable::Instance().InitBindingsFromCfg("OgreMaterialSoundBindings.cfg");

		SceneManager::Instance().PostInit();

		/*Ogre::TexturePtr t_depth = Ogre::TextureManager::getSingleton().createManual("rt_SceneDepth",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_FLOAT16_RGB, Ogre::TU_RENDERTARGET);
		Ogre::RenderTarget* depth_rtt = t_depth->getBuffer()->getRenderTarget();
		depth_rtt->addViewport(mCamera)->setOverlaysEnabled(false);
		depth_rtt->getViewport(0)->setShadowsEnabled(false);
		depth_rtt->getViewport(0)->setAutoUpdated(true);
		depth_rtt->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);
		depth_rtt->getViewport(0)->setClearEveryFrame(true);
		depth_rtt->getViewport(0)->setVisibilityMask(4294967281);
		depth_rtt->getViewport(0)->setMaterialScheme("depth");

		Ogre::TexturePtr t_volumetrics = Ogre::TextureManager::getSingleton().createManual("rt_VolumetricObjects",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_FLOAT16_RGB, Ogre::TU_RENDERTARGET);
		Ogre::RenderTarget* volumetrics_rtt = t_volumetrics->getBuffer()->getRenderTarget();
		volumetrics_rtt->addViewport(mCamera)->setOverlaysEnabled(false);
		volumetrics_rtt->getViewport(0)->setAutoUpdated(true);
		volumetrics_rtt->getViewport(0)->setShadowsEnabled(false);
		volumetrics_rtt->getViewport(0)->setClearEveryFrame(true);
		volumetrics_rtt->getViewport(0)->setVisibilityMask(2);
		volumetrics_rtt->getViewport(0)->setMaterialScheme("Volumetrics");*/


	};