Ejemplo n.º 1
0
Archivo: main.cpp Proyecto: Jadela/GT1
//Render the objects
void display()
{
	// Get CPU time from start.
	CPUtime = GetPerformanceTicks();

	// Initialize the physics time at the beginning of the program.
	if ( CPUphysicsTime == 0 )
		CPUphysicsTime = CPUtime - CPUphysicsTimeStep;

	while ( (CPUphysicsTime + CPUphysicsTimeStep) <= CPUtime )
	{
		physEngine.Update(physicsTimestep);
		CPUphysicsTime += CPUphysicsTimeStep;
	}

	//Make sure we do not get ahead of current time due to rounding errors
	if ( CPUphysicsTime > CPUtime )
		CPUphysicsTime = CPUtime;

	//Render section
	physEngine.Render();

	//Display the results
	glEnable( GL_BLEND );
	glPopMatrix();
	glutSwapBuffers();
	glClear( GL_COLOR_BUFFER_BIT );
}
Ejemplo n.º 2
0
TEST(Physics, collideEntityWithEntity) {
	PhysicsEngine phyEg;

	Vector2 initialPos(3.0f, 3.0f);
	Vector2 newPos(3.0f, 5.0f);

	Rectangle2 box(0.5f, 0.5f);
	auto ent = std::unique_ptr < TestEntity > (new TestEntity(initialPos, box));
	ent->setCollisionGroup(2);
	// collide with the floor and other from our collision group
	ent->setCollisionMask(CollisionGroups::Ground | 2);

	ent->setCollisionType(CollisionType::CircleDynamic);
	phyEg.registerEntity(ent.get());
	ent->setMoveIntent(newPos);

	// circle in between
	Rectangle2 circleCollide(1.0f, 1.0f);
	Vector2 wallPos(3.0f, 4.0f);
	auto entWall = std::unique_ptr < TestEntity > (new TestEntity(wallPos, circleCollide));
	entWall->setCollisionGroup(2);
	// collide with the floor and other from our collision group
	entWall->setCollisionMask(CollisionGroups::Ground | 2);

	entWall->setCollisionType(CollisionType::CircleDynamic);
	phyEg.registerEntity(entWall.get());
	//entWall->setMoveIntent(newPos);

	// run for one second
	// dont make this time to big, as bullet can only subdivide in a certain part of substeps
	phyEg.step(0.1f);
	std::cout << "is at " << ent->getMoveIntent() << std::endl;

	ASSERT_TRUE(ent->getMoveIntent().y() < newPos.y());
}
Ejemplo n.º 3
0
TEST(Physics, moveEntity) {
	PhysicsEngine phyEg;

	Vector2 initialPos(3.0f, 3.0f);
	Vector2 newPos(5.0f, 3.0f);

	Rectangle2 box(0.5f, 0.5f);
	auto ent = std::unique_ptr < TestEntity > (new TestEntity(initialPos, box));

	ent->setCollisionGroup(2);
	// collide with the floor and other from our collision group
	ent->setCollisionMask(CollisionGroups::Ground | 2);

	ent->setCollisionType(CollisionType::CircleDynamic);

	phyEg.registerEntity(ent.get());

	ent->setMoveIntent(newPos);

	// run for one second
	// dont make this time to big, as bullet can only subdivide in a certain part of substeps
	phyEg.step(0.1f);

	ASSERT_FLOAT_EQ(ent->getMoveIntent().x(), newPos.x());
	ASSERT_FLOAT_EQ(ent->getMoveIntent().y(), newPos.y());

	ASSERT_EQ(phyEg.getRegisteredEntitiesCount(), size_t(1));
}
Ejemplo n.º 4
0
void setupPhysics(ISceneManager* smgr)
{
	IMeshManager* meshManager = IMeshManager::getInstance();
	PhysicsEngine* engine = PhysicsEngine::getInstance();

	hkpRigidBodyCinfo groundInfo;
	hkVector4 groundSize(groundSize * 0.5f, 0.5, groundSize * 0.5f);
	hkpBoxShape* groundShape = new hkpBoxShape(groundSize, 0);
	groundInfo.m_shape = groundShape;
	groundInfo.m_motionType = hkpMotion::MOTION_FIXED;
	groundInfo.m_position.set(0.0f, -0.5, 0.0f);
	groundInfo.m_restitution = 0.9f;
	groundInfo.m_friction = 0.5f;

	hkpRigidBody* floorRigidBody = new hkpRigidBody(groundInfo);
	groundShape->removeReference();
	engine->addRigidBody(floorRigidBody);
	floorRigidBody->removeReference();

	// create BOX
	f32 boxHalfSize = 2.0f;
	ISimpleMesh* boxMesh = meshManager->createCubeMesh("box", boxHalfSize*2.0f,
		boxHalfSize * 2.0f, boxHalfSize*2.0f);
	IMeshNode* boxNode = smgr->addMeshNode(boxMesh, nullptr, nullptr, false);
	boxNode->setMaterialName("box_material");
	boxNode->addShadow(1);

	g_box = new PhysicsCube(boxNode, XMFLOAT3(boxHalfSize, boxHalfSize, boxHalfSize), XMFLOAT3(0, 40.0f, 0),
		false, 0.5f, 0.5f);
}
Ejemplo n.º 5
0
void RaceScene::Update(float dt)
{	
	if (mSceneManager->getActiveCameraNode() == mFreeCamera)
		updateCamera(mFreeCamera, dt);

	if (InputHandler::keyPressed(E_SWITCH_CAMERA))
	{
		if (mSceneManager->getActiveCameraNode() == mFreeCamera)
			mSceneManager->setActiveCamera(mFollowCamera);
		else {
			mFreeCamera->setPosition(mFollowCamera->getPosition());
			mSceneManager->setActiveCamera(mFreeCamera);
		}
	}

	if (mSceneManager->getActiveCameraNode() == mFreeCamera)
	{
		updateCamera(mFreeCamera, dt);
	}
	else
	{
		mPlayerVehicle->update(dt);
	}

	mGrassLand->update(dt);
	//mPlayerVehicle->update(dt);

	PhysicsEngine* engine = PhysicsEngine::getInstance();
	engine->update(dt);

	mSceneManager->update(dt);
}
Ejemplo n.º 6
0
PhysicsCube::PhysicsCube(IMeshNode* node, XMFLOAT3 halfExtends, XMFLOAT3 pos, 
	bool bStatic, f32 restitution, f32 friction)
:mMeshNode(node)
{
	hkpRigidBodyCinfo boxInfo;
	hkVector4 halfBoxSize(halfExtends.x, halfExtends.y, halfExtends.z);
	hkpBoxShape* boxShape = new hkpBoxShape(halfBoxSize, 0);

	boxInfo.m_shape = boxShape;
	boxInfo.m_position.set(pos.x, pos.y, pos.z);
	//boxInfo.m_motionType = hkpMotion::MOTION_DYNAMIC;
	boxInfo.m_restitution = restitution;
	boxInfo.m_friction = friction;
	boxInfo.m_motionType = (bStatic) ? hkpMotion::MOTION_FIXED : hkpMotion::MOTION_DYNAMIC;

	hkReal boxMass =  10.0f;
	hkMassProperties boxMassProperties;
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(halfBoxSize, boxMass, boxMassProperties);
	boxInfo.m_inertiaTensor = boxMassProperties.m_inertiaTensor;
	boxInfo.m_centerOfMass = boxMassProperties.m_centerOfMass;
	boxInfo.m_mass = boxMassProperties.m_mass;

	mRigidBody = new hkpRigidBody(boxInfo);
	boxShape->removeReference();

	PhysicsEngine* engine = PhysicsEngine::getInstance();

	engine->addRigidBody(mRigidBody);
}
Ejemplo n.º 7
0
void Application::Update(float deltaTime) {
    try {
        //Check for lost device
        HRESULT coop = g_pDevice->TestCooperativeLevel();

        if (coop != D3D_OK) {
            if (coop == D3DERR_DEVICELOST) {
                if (m_deviceLost == false)
                    DeviceLost();
            }
            else if (coop == D3DERR_DEVICENOTRESET) {
                if (m_deviceLost == true)
                    DeviceGained();
            }

            Sleep(100);
            return;
        }

        //Physics Engine
        physicsEngine.Update(deltaTime);

        if (KeyDown('1')) {
            physicsEngine.Reset(HINGE);
        }
        else if (KeyDown('2')) {
            physicsEngine.Reset(TWISTCONE);
        }
        else if (KeyDown('3')) {
            physicsEngine.Reset(BALLPOINT);
        }

        if (KeyDown(VK_LEFT))m_angle += deltaTime;
        if (KeyDown(VK_RIGHT))m_angle -= deltaTime;

        //Keyboard input
        if (KeyDown(VK_ESCAPE)) {
            Quit();
        }

        if (KeyDown(VK_RETURN) && KeyDown(18)) {     //ALT + RETURN
            //Switch between windowed mode and fullscreen mode
            m_present.Windowed = !m_present.Windowed;

            DeviceLost();
            DeviceGained();

            if (m_present.Windowed) {
                RECT rc = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
                AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);
                SetWindowPos(m_mainWindow, HWND_NOTOPMOST, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
                UpdateWindow(m_mainWindow);
            }
        }
    }
    catch(...) {
        g_debug << "Error in Application::Update() \n";
    }
}
Ejemplo n.º 8
0
void Application::Update(float deltaTime) {
    try {
        //Check for lost device
        HRESULT coop = g_pDevice->TestCooperativeLevel();

        if (coop != D3D_OK) {
            if (coop == D3DERR_DEVICELOST) {
                if (m_deviceLost == false)
                    DeviceLost();
            }
            else if (coop == D3DERR_DEVICENOTRESET) {
                if (m_deviceLost == true)
                    DeviceGained();
            }

            Sleep(100);
            return;
        }

        //Physics Engine
        physicsEngine.Update(m_slowMotion ? deltaTime * 0.1f : deltaTime * 1.0f);

        //reset simulation
        if (KeyDown(VK_SPACE)) {
            physicsEngine.Reset();
        }

        //Keyboard input
        if (KeyDown(VK_ESCAPE)) {
            Quit();
        }

        if (KeyDown(VK_RETURN) && KeyDown(18)) {     //ALT + RETURN
            //Switch between windowed mode and fullscreen mode
            m_present.Windowed = !m_present.Windowed;

            DeviceLost();
            DeviceGained();

            if (m_present.Windowed) {
                RECT rc = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
                AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);
                SetWindowPos(m_mainWindow, HWND_NOTOPMOST, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
                UpdateWindow(m_mainWindow);
            }
        }

        //Slowmotion on/off
        if (KeyDown(VK_RETURN)) {
            m_slowMotion = !m_slowMotion;
            Sleep(300);
        }

    }
    catch(...) {
        g_debug << "Error in Application::Update() \n";
    }
}
Ejemplo n.º 9
0
OBB* RagDoll::CreateBoneBox(Bone* parent, Bone *bone, D3DXVECTOR3 size, D3DXQUATERNION rot) {
    if (bone == NULL || parent == NULL)
        return NULL;

    D3DXMATRIX &parentMat = parent->CombinedTransformationMatrix;
    D3DXMATRIX &boneMat = bone->CombinedTransformationMatrix;
    D3DXVECTOR3 parentPos(parentMat(3, 0), parentMat(3, 1), parentMat(3, 2));
    D3DXVECTOR3 bonePos(boneMat(3, 0), boneMat(3, 1), boneMat(3, 2));

    D3DXQUATERNION q;
    D3DXVECTOR3 p, s;
    D3DXMatrixDecompose(&s, &q, &p, &parentMat);
    q *= rot;
    D3DXQuaternionNormalize(&q, &q);

    p = (parentPos + bonePos) * 0.5f;

    OBB *obb = new OBB(p, size, q, true);

    physicsEngine.GetWorld()->addRigidBody(obb->m_pBody);
    m_boxes.push_back(obb);

    parent->m_pObb = obb;
    parent->m_pivot = obb->SetPivot(parentPos);

    return obb;
}
Ejemplo n.º 10
0
void update(int value) {
    if (startStop == true) {
        game.moveParticle();

        if (flip1 == true || flip2 == true) {
            x++;//x is used to iterate over moving the flipper up then back down
            if (x < 13) { //increment by 0.1 to move flipper up. When x reaches 12, it'll reach its maximum which is -0.4
                moveY = moveY + 0.1;
                game.flipperStruct.movFlip1 = moveY;
            }
            else { //decrease by 0.1 to move flipper down
                moveY = moveY - 0.1;
                //                game.flipperStruct.movFlip1 = moveY;
                //                game.flipperStruct.movFlip2 = moveY;
            }
            if(x >= 25) { //if x = 25, flipper is at orginal position
                flip1 = false;
                flip2 = false;
                x = -1;
            }
        }
        if(game.ball.posY < -4) {
            gameOver = true;
        }
    }
    glutTimerFunc(10,update,0);
}
Ejemplo n.º 11
0
void RagDoll::CreateHinge(Bone* parent, OBB* A, OBB *B,
                          float upperLimit, float lowerLimit,
                          D3DXVECTOR3 hingeAxisA, D3DXVECTOR3 hingeAxisB,
                          bool ignoreCollisions) {
    if (parent == NULL || A == NULL || B == NULL)
        return;

    D3DXMATRIX &parentMat = parent->CombinedTransformationMatrix;
    btVector3 hingePos(parentMat(3, 0), parentMat(3, 1), parentMat(3, 2));
    D3DXVECTOR3 hingePosDX = D3DXVECTOR3(parentMat(3, 0), parentMat(3, 1), parentMat(3, 2));

    btRigidBody *a = A->m_pBody;
    btRigidBody *b = B->m_pBody;

    btTransform aTrans, bTrans;
    a->getMotionState()->getWorldTransform(aTrans);
    b->getMotionState()->getWorldTransform(bTrans);
    btVector3 aPos = aTrans.getOrigin();
    btVector3 bPos = bTrans.getOrigin();
    btQuaternion aRot = aTrans.getRotation();
    btQuaternion bRot = bTrans.getRotation();

    D3DXQUATERNION qa(aRot.x(), aRot.y(), aRot.z(), aRot.w());
    D3DXQUATERNION qb(bRot.x(), bRot.y(), bRot.z(), bRot.w());

    D3DXMATRIX matPosA, matPosB, matRotA, matRotB, worldA, worldB;
    D3DXMatrixTranslation(&matPosA, aPos.x(), aPos.y(), aPos.z());
    D3DXMatrixTranslation(&matPosB, bPos.x(), bPos.y(), bPos.z());
    D3DXMatrixRotationQuaternion(&matRotA, &qa);
    D3DXMatrixRotationQuaternion(&matRotB, &qb);
    D3DXMatrixMultiply(&worldA, &matRotA, &matPosA);
    D3DXMatrixMultiply(&worldB, &matRotB, &matPosB);

    D3DXVECTOR3 offA(0.0f, A->m_size.y * -0.5f, 0.0f);
    D3DXVECTOR3 offB(0.0f, B->m_size.y * 0.5f, 0.0f);

    D3DXMatrixInverse(&worldA, NULL, &worldA);
    D3DXMatrixInverse(&worldB, NULL, &worldB);

    D3DXVec3TransformCoord(&offA, &hingePosDX, &worldA);
    D3DXVec3TransformCoord(&offB, &hingePosDX, &worldB);

//  btVector3 offsetA(aPos.x() - hingePos.x(), aPos.y() - hingePos.y(), aPos.z() - hingePos.z());
//  btVector3 offsetB(bPos.x() - hingePos.x(), bPos.y() - hingePos.y(), bPos.z() - hingePos.z());

    btVector3 offsetA(offA.x, offA.y, offA.z);
    btVector3 offsetB(offB.x, offB.y, offB.z);

    aTrans.setIdentity();
    bTrans.setIdentity();
    aTrans.setOrigin(offsetA);
    bTrans.setOrigin(offsetB);
    aTrans.getBasis().setEulerZYX(hingeAxisA.x, hingeAxisA.y, hingeAxisA.z);
    bTrans.getBasis().setEulerZYX(hingeAxisB.x, hingeAxisB.y, hingeAxisB.z);

    btHingeConstraint *hingeC = new btHingeConstraint(*b, *a, bTrans, aTrans);
    hingeC->setLimit(lowerLimit, upperLimit);
    physicsEngine.GetWorld()->addConstraint(hingeC, ignoreCollisions);
}
Ejemplo n.º 12
0
void updatePhysics(f32 dt)
{
	//	physicsWorld->stepDeltaTime(dt);

	if (dt > 0)
	{
		PhysicsEngine* engine = PhysicsEngine::getInstance();
		engine->update(dt);
		g_box->update(dt);
		
		for (u32 i = 0; i < g_boxes.size(); i++)
		{
			g_boxes[i]->update(dt);
		}

	}
}
Ejemplo n.º 13
0
Archivo: main.cpp Proyecto: hef/siggame
int main( int argc, char **argv )
{
	if ( argc == 2 && strncmp( argv[1], "editor", 6 ) )
	{
		// Run the editor
	}

	//Initialize everything
	Renderer* r = Renderer::getInstanceOf();
	AudioSystem* audio = AudioSystem::getInstance();
	PhysicsEngine* p = PhysicsEngine::Instance();
	Input* input = Input::Instance();
	World* w = World::getInstance();
	audio->addSound( "Mac.wav" );
	audio->addSound( "doh.wav" );
	audio->playSound( "Mac.wav" );
	static unsigned int lastTime = SDL_GetTicks();
	static unsigned int currentTime = lastTime;
	static double dt = 0;
	bool bShouldExit = false;
	//Start main loop, runs until esc is pressed
	do
	{
		currentTime = SDL_GetTicks();
		dt = static_cast<double>( currentTime - lastTime ) / 1000;
		lastTime = currentTime;
		//Update keyboard state
		input->tick( dt );
		bShouldExit = input->escKeyDown();
		//process world logic
		w->tick( dt );
		p->applyPhysics( *w );
		//Rerender the world every iteration
		r->render( *w );
	}
	while ( !bShouldExit );
	//delete the instances
	audio->destroy();
	p->destroy();
	input->destroy();
	r->destroy();
	w->destroy();
	return EXIT_SUCCESS;
}
Ejemplo n.º 14
0
int main(int argc, char** argv)
{
	Viewport window("The People of Earth TestBed ***Demo***", 800, 600/*1920, 1080*/, 0);
	GUIEngine guiEngine("Assets/GUI");
	RenderingEngine renderingEngine(window);
	SceneManager sceneManager(&window);
	PhysicsEngine physicsEngine;
	physicsEngine.getPhysicsWorld()->init(PxVec3(0.0f, 0.0f, 0.0f), 20000.0f);
	AudioEngine audioEngine;

	CoreEngine core(60.0, &window, &renderingEngine, &physicsEngine, &audioEngine, &guiEngine, &sceneManager);

	sceneManager.push(new TestScene, Modality::Exclusive);

	core.start();

	return 0;

}
Ejemplo n.º 15
0
TEST(Physics, changeCollisionGroup) {
	PhysicsEngine phyEg;

	const Vector2 initialPos(3.0f, 3.0f);
	const Vector2 newPos(3.0f, 5.0f);

	Rectangle2 box(0.5f, 0.5f);
	auto ent = std::unique_ptr < TestEntity > (new TestEntity(initialPos, box));
	ent->setCollisionGroup(2);
	// collide with the floor and other from our collision group
	ent->setCollisionMask(CollisionGroups::Ground | 2);

	ent->setCollisionType(CollisionType::CircleDynamic);
	phyEg.registerEntity(ent.get());
	ent->setMoveIntent(newPos);

	// change collision settings after registering
	ent->setCollisionMask(0);

	// box in between
	Rectangle2 boxCollide(5.0f, 0.5f);
	Vector2 wallPos(3.0f, 4.0f);
	auto entWall = std::unique_ptr < TestEntity > (new TestEntity(wallPos, boxCollide));
	entWall->setCollisionGroup(2);
	// collide with the floor and other from our collision group
	entWall->setCollisionMask(CollisionGroups::Ground | 2);

	entWall->setCollisionType(CollisionType::BoxStatic);
	phyEg.registerEntity(entWall.get());

	phyEg.step(0.1f);

	std::cout << "is at " << ent->getMoveIntent() << std::endl;

	EXPECT_NEAR(ent->getMoveIntent().x(), newPos.x(), 0.001);
	EXPECT_NEAR(ent->getMoveIntent().y(), newPos.y(), 0.001);

}
Ejemplo n.º 16
0
void MyWindow::draw() {
	if( !valid() ) {
		GLenum err = glewInit(); 
		if (err != GLEW_OK) 
			exit(1);
		if (!GLEW_VERSION_3_3)
			exit(1);
		pe.Init();
		ve.Init();
		objects.push_back(Object(&pe,numv)); //Requires glewInit to be run.
	}
	Vstep();

	glDrawBuffer(GL_BACK);
}
Ejemplo n.º 17
0
void Application::Render() {
    if (!m_deviceLost) {
        try {
            // Clear the viewport
            g_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L);

            // Begin the scene
            if (SUCCEEDED(g_pDevice->BeginScene())) {
                D3DXMATRIX view, proj;
                D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 2.0f, -10.0f), &D3DXVECTOR3(0.0f, 2.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
                D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 1000.0f);

                g_pEffect->SetMatrix("matVP", &(view * proj));

                D3DXVECTOR4 lightPos(-20.0f, 75.0f, -120.0f, 0.0f);
                g_pEffect->SetVector("lightPos", &lightPos);

                //Render All Physics Objects
                physicsEngine.Render();

                RECT rc = {10, 590, 0, 590};
                g_pFont->DrawText(NULL, "Press Space to restart simulation.", -1, &rc, DT_LEFT | DT_BOTTOM | DT_NOCLIP, 0x88000000);

                RECT rc2 = {10, 570, 0, 570};
                string s = "Press Return to toggle slowmotion: ";
                s += (m_slowMotion ? "ON" : "OFF");
                g_pFont->DrawText(NULL, s.c_str(), -1, &rc2, DT_LEFT | DT_BOTTOM | DT_NOCLIP, 0x88000000);

                // End the scene.
                g_pDevice->EndScene();
                g_pDevice->Present(0, 0, 0, 0);
            }
        }
        catch(...) {
            g_debug << "Error in Application::Render() \n";
        }
    }
}
Ejemplo n.º 18
0
void Application::Render() {
    if (!m_deviceLost) {
        try {
            // Clear the viewport
            g_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L);

            // Begin the scene
            if (SUCCEEDED(g_pDevice->BeginScene())) {
                D3DXMATRIX view, proj;
                D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(cos(m_angle) * 15.0f, 5.0f, sin(m_angle) * 15.0f), &D3DXVECTOR3(0.0f, 2.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
                D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 3.0f, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 1000.0f);

                g_pEffect->SetMatrix("matVP", &(view * proj));

                D3DXVECTOR4 lightPos(-20.0f, 75.0f, -120.0f, 0.0f);
                g_pEffect->SetVector("lightPos", &lightPos);

                //Render All Physics Objects
                physicsEngine.Render();

                RECT rc1 = {10, 10, 0, 590};
                g_pFont->DrawText(NULL, "Press 1: Use Hinge Constraints.", -1, &rc1, DT_LEFT | DT_TOP | DT_NOCLIP, 0x88000000);
                RECT rc2 = {10, 30, 0, 590};
                g_pFont->DrawText(NULL, "Press 2: Use Twist-Cone Constraints.", -1, &rc2, DT_LEFT | DT_TOP | DT_NOCLIP, 0x88000000);
                RECT rc3 = {10, 50, 0, 590};
                g_pFont->DrawText(NULL, "Press 3: Use Point-2-Point Constraints.", -1, &rc3, DT_LEFT | DT_TOP | DT_NOCLIP, 0x88000000);

                // End the scene.
                g_pDevice->EndScene();
                g_pDevice->Present(0, 0, 0, 0);
            }
        }
        catch(...) {
            g_debug << "Error in Application::Render() \n";
        }
    }
}
Ejemplo n.º 19
0
Archivo: main.cpp Proyecto: Jadela/GT1
//Initialise the render world
void init()
{
	glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );
	//glEnable( GL_CULL_FACE );
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glClearColor( 0, 0.0, 0.0, 0.0 );

	// Light 0 parameters
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_ambient[] = { 0.3, 0.3, 0.3, 1.0 };
	GLfloat light_position[] = { 1.0, 0.0, 1.0, 0.0 };

	// Setup light 0
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glLightfv(GL_LIGHT0, GL_AMBIENT, mat_ambient); 
	glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_specular);

	// Turn light on! :)
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_COLOR_MATERIAL);
	
	physEngine.Init();
}
Ejemplo n.º 20
0
Archivo: main.cpp Proyecto: Jadela/GT1
//Key handling
void process_keys(unsigned char i_key, int i_x, int i_y)
{
	Rigidbody* subject = physEngine.GetRigidbody(0);
	switch ( i_key ) {
		//numpad
		case '0' :
			subject->ApplyForce(vec3(SQR_FORCE_APPLIED, SQR_FORCE_APPLIED, 0), subject->GetPos() + vec3(0.0f, 0.0f, -0.5f));
		break;
		case '1' :
			subject->ApplyForce(vec3(SQR_FORCE_APPLIED, SQR_FORCE_APPLIED, 0), subject->GetPos() + vec3(1.0f, 1.0f, 0.0f));
		break;
		case '2' :
			subject->ApplyForce(vec3(0, FORCE_APPLIED, 0), subject->GetPos() + vec3(0.0f, 1.0f, 0.0f));
		break;
		case '3' :
			subject->ApplyForce(vec3(SQR_FORCE_APPLIED, SQR_FORCE_APPLIED, 0), subject->GetPos() + vec3(-1.0f, 1.0f, 0.0f));
		break;
		case '4' :
			subject->ApplyForce(vec3(FORCE_APPLIED, 0, 0), subject->GetPos() + vec3(1.0f, 0.0f, 0.0f));
		break;
		case '5' :
			subject->ApplyForce(vec3(SQR_FORCE_APPLIED, SQR_FORCE_APPLIED, 0), subject->GetPos() + vec3(0.0f, 0.0f, 0.5f));
		break;
		case '6' :
			subject->ApplyForce(vec3(FORCE_APPLIED, 0, 0), subject->GetPos() + vec3(-1.0f, 0.0f, 0.0f));
		break;
		case '7' :
			subject->ApplyForce(vec3(SQR_FORCE_APPLIED, SQR_FORCE_APPLIED, 0), subject->GetPos() + vec3(1.0f, -1.0f, 0.0f));
		break;
		case '8' :
			subject->ApplyForce(vec3(0, -FORCE_APPLIED, 0), subject->GetPos() + vec3(0.0f, -1.0f, 0.0f));
		break;
		case '9' :
			subject->ApplyForce(vec3(SQR_FORCE_APPLIED, SQR_FORCE_APPLIED, 0), subject->GetPos() + vec3(-1.0f, -1.0f, 0.0f));
		break;
		//z (test case)
		case 'z' :
			subject->ApplyForce(vec3(FORCE_APPLIED, 0, 0), subject->GetPos() + vec3(-1.0f, 0.2f, 0.1f));
		break;
		case 'w':
			subject->m_F = vec3(0.0f, FORCE_APPLIED, 0.0f);
		break;
		case 's':
			subject->m_F = vec3(0.0f, -FORCE_APPLIED, 0.0f);
		break;
		case 'a':
			subject->m_F = vec3(-FORCE_APPLIED, 0.0f, 0.0f);
		break;
		case 'd':
			subject->m_F = vec3(FORCE_APPLIED, 0.0f, 0.0f);
		break;			
		case 'e':
			subject->m_F = vec3(0.0f, 0.0f, -FORCE_APPLIED);
		break;
		case 'q':
			subject->m_F = vec3(0.0f, 0.0f, FORCE_APPLIED);
		break;
		case 'o':
			subject->m_T = vec3(0.0f, FORCE_APPLIED, FORCE_APPLIED);
		break;			
		case 'u':
			subject->m_T = vec3(0.0f, -FORCE_APPLIED, -FORCE_APPLIED);
		break;
		case 'n':
			physEngine.SetWind(physEngine.m_Wind + vec3(0.1f, 0.0f, 0.0f));
			break;
		case 'm':
			physEngine.SetWind(physEngine.m_Wind + vec3(-0.1f, 0.0f, 0.0f));
		default:
		break;
	}
}
Ejemplo n.º 21
0
void TestGame::Init(const Window& window)
{
	//Materials
	Material bricks("bricks", Texture("bricks.jpg"), 0.0f, 0, Texture("bricks_normal.jpg"), Texture("bricks_disp.png"), 0.03f, -0.5f);
	Material bricks2("bricks2", Texture("bricks2.jpg"), 0.0f, 0, Texture("bricks2_normal.png"), Texture("bricks2_disp.jpg"), 0.04f, -1.0f);

	//Standard square mesh (1x1)
	IndexedModel square;
	{
		square.AddVertex(1.0f, -1.0f, 0.0f);  square.AddTexCoord(Vector2f(1.0f, 1.0f));
		square.AddVertex(1.0f, 1.0f, 0.0f);   square.AddTexCoord(Vector2f(1.0f, 0.0f));
		square.AddVertex(-1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 1.0f));
		square.AddVertex(-1.0f, 1.0f, 0.0f);  square.AddTexCoord(Vector2f(0.0f, 0.0f));
		square.AddFace(0, 1, 2); square.AddFace(2, 1, 3);
	}
	Mesh customMesh("square", square.Finalize());

	//Light
	Entity* mainLight = new Entity(Vector3f(0, 4, 0), Quaternion(Vector3f(1, 0, 0), ToRadians(270)), 1);
	Entity* pointLight = new Entity(Vector3f(-1, 1.5, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1);

	mainLight->AddModifier(new DirectionalLight(Vector3f(1, 1, 1), 0.4f, 10, 80, 1));
	pointLight->AddModifier(new PointLight(Vector3f(0, 0, 1), 0.4f, Attenuation(0, 0, 1)));
	pointLight->AddModifier(new RepetitiveLinearMotionModifier(Vector3f(1, 0, 0), 0.015f, 1));
	//pointLight->AddModifier(new FreeMove(5.0f));

	AddToScene(mainLight);
	//AddToScene(pointLight);

	//Camera
	Entity* mainCamera = new Entity(Vector3f(-10, 5, 5), Quaternion(Vector3f(0, 0, 0), 0), 1);

	mainCamera->AddModifier(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70), window.GetAspect(), 0.1f, 1000)));
	mainCamera->AddModifier(new FreeLook(window.GetCenter(), 0.15f));
	mainCamera->AddModifier(new FreeMove(15));

	AddToScene(mainCamera);

	//Environment
	/*Entity* floorPlane = new Entity(Vector3f(0, 0, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1);
	Entity* floatingCube = new Entity(Vector3f(0, 1, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 0.3f);

	floorPlane->AddModifier(new MeshRenderer(Mesh("plane.obj"), Material("bricks")));
	floatingCube->AddModifier(new MeshRenderer(Mesh("cube.obj"), Material("bricks2")));
	floatingCube->AddModifier(new RepetitiveLinearMotionModifier(Vector3f(0, 1, 0), 0.01f, 2));
	floatingCube->AddModifier(new RepetitiveRotationalMotionModifier(Vector3f(0, 1, 0), 0.02f, 1, false));

	AddToScene(floorPlane);
	AddToScene(floatingCube);*/

	Entity* sphere1 = new Entity(Vector3f(0, 0, -4), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1);
	Entity* sphere2 = new Entity(Vector3f(0, 0, 1), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1);
	Entity* sphere3 = new Entity(Vector3f(0, 0, 3), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1);
	Entity* sphere4 = new Entity(Vector3f(0, 0, 5), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1);
	Entity* sphere5 = new Entity(Vector3f(0, 0, 7), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1);

	sphere1->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks")));
	sphere2->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2")));
	sphere3->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2")));
	sphere4->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2")));
	sphere5->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks")));

	AddToScene(sphere1);
	AddToScene(sphere2);
	AddToScene(sphere3);
	AddToScene(sphere4);
	AddToScene(sphere5);

	//Physics
	PhysicsEngine physicsEngine = PhysicsEngine();

	PhysicsObject sphere1Rep = PhysicsObject(sphere1, new BoundingSphere(Vector3f(0, 0, -4), 1), Vector3f(0, 0, 1), Vector3f(0, 0, 0), false);
	PhysicsObject sphere2Rep = PhysicsObject(sphere2, new BoundingSphere(Vector3f(0, 0, 1), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false);
	PhysicsObject sphere3Rep = PhysicsObject(sphere3, new BoundingSphere(Vector3f(0, 0, 3), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false);
	PhysicsObject sphere4Rep = PhysicsObject(sphere4, new BoundingSphere(Vector3f(0, 0, 5), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false);
	PhysicsObject sphere5Rep = PhysicsObject(sphere5, new BoundingSphere(Vector3f(0, 0, 7), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false);

	physicsEngine.AddObject(sphere1Rep);
	physicsEngine.AddObject(sphere2Rep);
	physicsEngine.AddObject(sphere3Rep);
	physicsEngine.AddObject(sphere4Rep);
	physicsEngine.AddObject(sphere5Rep);

	SetPhysicsEngine(physicsEngine);
}
Ejemplo n.º 22
0
Archivo: Main.cpp Proyecto: rdoo/inz
void display() {
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Set background color to black and opaque
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the color buffer

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glScalef(dynamicZoom, dynamicZoom, dynamicZoom);

	gluLookAt(camera.mPos.x(), camera.mPos.y(), camera.mPos.z(),
			camera.mView.x(), camera.mView.y(), camera.mView.z(),
			camera.mUp.x(), camera.mUp.y(), camera.mUp.z());

	if (axesEnabled)
		drawAxes();

	for (int i = 0; i < numberOfAtoms; i++) {
		displayAtom(i);
	}

	std::ostringstream titleStr, energyStr, stepStr, lastStr, workStr;

	//workStr << "[WORK IN PROGRESS]";

	if (state == algorithm) { // TODO: do poprawy
		titleStr << "MONTE CARLO ALGORITHM";
	} else if (state == physics) {
		std::ostringstream timeStr;
		titleStr << "SYSTEM EVOLUTION OVER TIME";
		timeStr << "Virtual simulation time in ns: "
				<< (double) physxEngine.timeFromBeginning() * 1.e9 << std::endl;

		writeString(timeStr.str(), -1., .75);
	}

	if (lastState == algorithm)
		energyStr << "Total energy: "
				<< (double) algoEngine.currentEnergy / elementaryCharge
				<< " eV";
	else if (lastState == physics)
		energyStr << "Total energy: "
				<< (double) physxEngine.currentEnergy / elementaryCharge
				<< " eV";
	else if (algoEngine.currentEnergy < physxEngine.currentEnergy)
		energyStr << "Total energy: "
				<< (double) algoEngine.currentEnergy / elementaryCharge
				<< " eV";
	else
		energyStr << "Total energy: "
				<< (double) physxEngine.currentEnergy / elementaryCharge
				<< " eV";

	stepStr << "Step number: " << algoEngine.steps;
	lastStr << "Last change at step: " << algoEngine.lastChangeStep;

	writeString(workStr.str(), -1., -1.);
	writeString(titleStr.str(), -1., .95);
	writeString(energyStr.str(), -1., .90);
	writeString(stepStr.str(), -1., .85);
	writeString(lastStr.str(), -1., .80);

	glFlush();  // Render now

}
Ejemplo n.º 23
0
void Scene02::init(const Window& window)
{
    Camera camera(50.0f, window.getAspectRatio(), 0.1f, 100.0f);
    CameraComponent* cameraComponent = new CameraComponent(camera);

    PhysicsEngine physicsEngine;
    PhysicsObject physicsObject1(new BoundingSphere(glm::vec3(-1.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    PhysicsObject physicsObject2(new BoundingSphere(glm::vec3(-2.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    PhysicsObject physicsObject3(new BoundingSphere(glm::vec3(-3.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    PhysicsObject physicsObject4(new BoundingSphere(glm::vec3(-4.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    PhysicsObject physicsObject5(new BoundingSphere(glm::vec3(-5.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);
    //PhysicsObject physicsObject6(new BoundingSphere(glm::vec3(-6.0, 0.5, -5.0), 0.2f), glm::vec3(0.1f, 0.1f, 0.0f), true);

    //PhysicsObject physicsObject6(new BoundingSphere(glm::vec3(3.0, 0.0, -5.0), 0.1f), glm::vec3(0.0f, 0.0f, 0.0f), false);

    physicsEngine.addObject(physicsObject1);
    physicsEngine.addObject(physicsObject2);
    physicsEngine.addObject(physicsObject3);
    physicsEngine.addObject(physicsObject4);
    physicsEngine.addObject(physicsObject5);
    //physicsEngine.addObject(physicsObject6);

    PhysicsEngineComponent* physicsEngineComponent = new PhysicsEngineComponent(physicsEngine);
    Node* physicsEngineNode = new Node;
    physicsEngineNode->addComponent(physicsEngineComponent);
    addToScene(physicsEngineNode);

    IndexedMesh floorIndexedMesh("models/plane.obj");
    floorIndexedMesh.m_texCoords.push_back( glm::vec2(1.0, 1.0) );
    floorIndexedMesh.m_texCoords.push_back( glm::vec2(1.0, 0.0) );
    floorIndexedMesh.m_texCoords.push_back( glm::vec2(0.0, 0.0) );
    floorIndexedMesh.m_texCoords.push_back( glm::vec2(0.0, 1.0) );
    Mesh floorMesh;
    floorMesh.init(floorIndexedMesh);
    Material* floor = new Material( new Texture("textures/snow.jpg") , glm::vec3(1.0, 1.0, 1.0));

    // adding interior
    Material* back = new Material( new Texture("textures/Fireplace.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* backNode = new Node(glm::vec3(-10.0, 8.0, -10.0), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(20.0f, 1.0f, 10.0f));
    backNode->addComponent(new MeshRenderer(floorMesh, *back));
    addToScene(backNode);

    Material* win = new Material( new Texture("textures/s.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* winNode = new Node(glm::vec3(9.99, 10.0, -10.0), glm::vec3(0.0f, -90.0f, -90.0f), glm::vec3(5.0f, 1.0f, 5.0f));
    winNode->addComponent(new MeshRenderer(floorMesh, *win));
    addToScene(winNode);

    Node* winNode2 = new Node(glm::vec3(10.01, 10.0, -10.0), glm::vec3(0.0f, -90.0f, -90.0f), glm::vec3(5.0f, 1.0f, 5.0f));
    winNode2->addComponent(new MeshRenderer(floorMesh, *win));
    addToScene(winNode2);

    Material* walls = new Material( new Texture("textures/carpet5.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* roofNode = new Node(glm::vec3(-10.0, 18.0, -10.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(20.0f, 1.0f, 20.0f));
    roofNode->addComponent(new MeshRenderer(floorMesh, *walls));
    addToScene(roofNode);

    Node* rwallNode = new Node(glm::vec3(10.0, 8.0, -10.0), glm::vec3(0.0f, 0.0f, -90.0f), glm::vec3(13.0f, 1.0f, 20.0f));
    rwallNode->addComponent(new MeshRenderer(floorMesh, *walls));
    addToScene(rwallNode);

    Material* fwall = new Material( new Texture("textures/Door.jpg") , glm::vec3(1.0, 1.0, 1.0));
     Node* fwallNode = new Node(glm::vec3(-30.0, 8.0, -10.0), glm::vec3(0.0f, 90.0f, -90.0f), glm::vec3(13.0f, 1.0f, 20.0f));
    fwallNode->addComponent(new MeshRenderer(floorMesh, *fwall));
    addToScene(fwallNode);

    Material* flor = new Material( new Texture("textures/carpet4.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* florNode = new Node(glm::vec3(-10.0, -0.99, -10.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(20.0f, 1.0f, 20.0f));
    florNode->addComponent(new MeshRenderer(floorMesh, *flor));
    addToScene(florNode);

    Material* bg1 = new Material( new Texture("textures/n.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* bgNode = new Node(glm::vec3(0.0, 8.0, -10.0), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(30.0f, 1.0f, 10.0f));
    bgNode->addComponent(new MeshRenderer(floorMesh, *bg1));
    addToScene(bgNode);

    Node* bgNode2 = new Node(glm::vec3(30.0, 8.0, -10.0), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(30.0f, 1.0f, 10.0f));
    bgNode2->addComponent(new MeshRenderer(floorMesh, *bg1));
    addToScene(bgNode2);

       Node* bgNode3 = new Node(glm::vec3(90.0, 8.0, -10.0), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(30.0f, 1.0f, 10.0f));
    bgNode3->addComponent(new MeshRenderer(floorMesh, *bg1));
    addToScene(bgNode3);

    // finishing interior

    Node* floorNode = new Node(glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(50.0f, 1.0f, 10.0f));
    floorNode->addComponent(new MeshRenderer(floorMesh, *floor));
    addToScene(floorNode);

    Material* bg = new Material( new Texture("textures/bg2.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Node* bgNode1 = new Node(glm::vec3(0.0, 2.5, -10.0), glm::vec3(90.0f, 0.0f, 0.0f), glm::vec3(50.0f, 1.0f, 5.0f));
    bgNode1->addComponent(new MeshRenderer(floorMesh, *bg));
    addToScene(bgNode1);

    Mesh* cubeMesh = new Mesh;
    cubeMesh->initCube();
    //Material* building = new Material( new Texture("textures/igloo.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Material* gift = new Material( new Texture("textures/xmas.jpg") , glm::vec3(1.0, 1.0, 1.0));

//    Node* cubeNode1 = new Node(glm::vec3(3.0, 0.0, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
//    cubeNode1->addComponent(new MeshRenderer(*cubeMesh, *building));
//    //cubeNode1->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(5)));
//    addToScene(cubeNode1);
//
//    Node* cubeNode2 = new Node(glm::vec3(13.0, 0.0, -6.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
//    cubeNode2->addComponent(new MeshRenderer(*cubeMesh, *building));
//    addToScene(cubeNode2);

    Material* building = new Material( new Texture("textures/e.jpg") , glm::vec3(1.0, 1.0, 1.0));
    Material* outer = new Material( new Texture("textures/igloo.jpg") , glm::vec3(1.0, 1.0, 1.0));

    Node* cubeNode1 = new Node(glm::vec3(3.0, 0.0, -6.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
    cubeNode1->addComponent(new MeshRenderer(*cubeMesh, *building));
    addToScene(cubeNode1);

    Node* cubeNode2 = new Node(glm::vec3(13.0, 0.0, -6.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
    cubeNode2->addComponent(new MeshRenderer(*cubeMesh, *outer));
    addToScene(cubeNode2);

    Node* cubeNode3 = new Node(glm::vec3(23.0, 0.0, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
    cubeNode3->addComponent(new MeshRenderer(*cubeMesh, *outer));
    addToScene(cubeNode3);

     Node* cubeNode4 = new Node(glm::vec3(-3.0, 0.0, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
    cubeNode4->addComponent(new MeshRenderer(*cubeMesh, *building));
    addToScene(cubeNode4);

//    Node* cubeNode3 = new Node(glm::vec3(23.0, 0.0, -6.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f));
//    cubeNode3->addComponent(new MeshRenderer(*cubeMesh, *building));
//    addToScene(cubeNode3);

    Node* xmasNode = new Node(glm::vec3(33.0, 0.0, -6.0), glm::vec3(90.0f, 0.0f, 0.0f), glm::vec3(3.0f, 1.0f, 1.0f));
    xmasNode->addComponent(new MeshRenderer(floorMesh, *gift));
    addToScene(xmasNode);

    IndexedMesh paperPlaneIndexedMesh("models/paperbird.obj");
    Mesh paperPlaneMesh;
    paperPlaneMesh.init(paperPlaneIndexedMesh);

    Material* yellowPaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.95, 0.95, 0.25));
    Node* birdNode1 = new Node(glm::vec3(-1.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode1->addComponent(new MeshRenderer(paperPlaneMesh, *yellowPaper));
    birdNode1->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(0)));
    birdNode1->addComponent(cameraComponent);
    addToScene(birdNode1);

    Material* orangePaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.93, 0.67, 0.09));
    Node* birdNode2 = new Node(glm::vec3(-2.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode2->addComponent(new MeshRenderer(paperPlaneMesh, *orangePaper));
    birdNode2->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(1)));
    addToScene(birdNode2);

    Material* redPaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.9, 0.28, 0.28));
    Node* birdNode3 = new Node(glm::vec3(-3.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode3->addComponent(new MeshRenderer(paperPlaneMesh, *redPaper));
    birdNode3->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(2)));
    addToScene(birdNode3);

    Material* greenPaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.43, 0.79, 0.43));
    Node* birdNode4 = new Node(glm::vec3(-4.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode4->addComponent(new MeshRenderer(paperPlaneMesh, *greenPaper));
    birdNode4->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(3)));
    addToScene(birdNode4);

    Material* bluePaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(0.27, 0.51, 0.78));
    Node* birdNode5 = new Node(glm::vec3(-5.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    birdNode5->addComponent(new MeshRenderer(paperPlaneMesh, *bluePaper));
    birdNode5->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(4)));
    addToScene(birdNode5);

//    Material* whitePaper = new Material( new Texture("textures/paper.jpg") , glm::vec3(1.0, 1.0, 1.0));
//    Node* birdNode6 = new Node(glm::vec3(-6.0, 0.5, -5.0), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 0.5f));
//    birdNode6->addComponent(new MeshRenderer(paperPlaneMesh, *whitePaper));
//    birdNode6->addComponent(new PhysicsObjectComponent(&physicsEngineComponent->getPhysicsEngine().getObject(5)));
//    addToScene(birdNode6);

}
Ejemplo n.º 24
0
Archivo: Main.cpp Proyecto: rdoo/inz
void update(int value) {
	handleKeyboard();
	camera.mouseMove();

	if (rotateEnabled)
		camera.rotateView(0.001);

	switch (state) {
	case pause:
		lastState = pause;
		break;
	case algorithm:
		lastState = algorithm;
		for (int i = 0; i < numberOfSteps; i++) {
			algoEngine.step(atomTable, numberOfAtoms);
		}
		//pliku << algoEngine.steps << " " << (double) (algoEngine.currentEnergy / elementaryCharge / numberOfAtoms) << std::endl;

		resetAtomsVelocities(atomTable, numberOfAtoms);
		break;
	case physics:
		lastState = physics;
		for (int i = 0; i < numberOfSteps; i++) {
			physxEngine.step(atomTable, numberOfAtoms);
		}
		break;
	case reset:
		generateAtoms(atomTable, numberOfAtoms, diameter, atomMass);
		//generateAtomsInCube(atomTable, numberOfAtoms, 2.5e-10, atomMass,
		//		rows, columns);
		algoEngine.currentEnergy = algoEngine.configurationEnergy(atomTable, numberOfAtoms);
		algoEngine.steps = 0;
		algoEngine.lastChangeStep = 0;
		algoEngine.temp = 750;
		physxEngine.resetTime();
		state = pause;
		break;
	case a2:
		numberOfAtoms = 2;
		atomTable = new Atom[numberOfAtoms];
		rows = 2;
		columns = 1;
		state = reset;
		break;
	case a5:
		numberOfAtoms = 5;
		atomTable = new Atom[numberOfAtoms];
		rows = 3;
		columns = 2;
		state = reset;
		break;
	case a10:
		numberOfAtoms = 10;
		atomTable = new Atom[numberOfAtoms];
		rows = 4;
		columns = 3;
		state = reset;
		break;
	case a15:
		numberOfAtoms = 15;
		atomTable = new Atom[numberOfAtoms];
		rows = 4;
		columns = 4;
		state = reset;
		break;
	case a20:
		numberOfAtoms = 20;
		atomTable = new Atom[numberOfAtoms];
		rows = 5;
		columns = 4;
		state = reset;
		break;
	case a50:
		numberOfAtoms = 50;
		atomTable = new Atom[numberOfAtoms];
		rows = 8;
		columns = 7;
		state = reset;
		break;
	case a100:
		numberOfAtoms = 100;
		atomTable = new Atom[numberOfAtoms];
		rows = 10;
		columns = 10;
		state = reset;
		break;
	case s1:
		numberOfSteps = 1;
		state = lastState;
		break;
	case s5:
		numberOfSteps = 5;
		state = lastState;
		break;
	case s10:
		numberOfSteps = 10;
		state = lastState;
		break;
	case s30:
		numberOfSteps = 30;
		state = lastState;
		break;
	case s50:
		numberOfSteps = 50;
		state = lastState;
		break;
	case s100:
		numberOfSteps = 100;
		state = lastState;
		break;
	case s1000:
		numberOfSteps = 1000;
		state = lastState;
		break;
	case axes:
		axesEnabled = axesEnabled ? false : true;
		state = lastState;
		break;
	case rotate:
		rotateEnabled = rotateEnabled ? false : true;
		state = lastState;
		break;
	case read: {
		std::ifstream reader;
		reader.open(readFile.c_str());
		int ratoms, rsteps, rlastchange;
		long double renergy;
		std::string line;

		std::getline(reader, line);
		ratoms = atoi(line.substr(2, 3).c_str());
		std::getline(reader, line);
		rsteps = atoi(line.substr(2, 10).c_str());
		std::getline(reader, line);
		rlastchange = atoi(line.substr(2, 10).c_str());
		std::getline(reader, line);
		renergy = atof(line.substr(2, 10).c_str());

		algoEngine.steps = rsteps;
		algoEngine.lastChangeStep = rlastchange;
		algoEngine.currentEnergy = renergy * elementaryCharge;
		numberOfAtoms = ratoms;
		atomTable = new Atom[numberOfAtoms]; //TODO :zmienic
		Atom atom;
		Vector position;
		int i = 0;
		long double x, y, z;
		while (std::getline(reader, line)) {
			std::istringstream iss(line);
			iss >> x;
			iss >> y;
			iss >> z;
			position = Vector(x, y, z);
			atom = Atom(atomMass, position, Vector(0., 0., 0.));
			atomTable[i] = atom;
			i++;
		}
		reader.close();
	}

		state = pause;
		break;
	case rr:
		readFile = "random.txt";
		state = read;
		break;
	case r5:
		readFile = "5.txt";
		state = read;
		break;
	case r10:
		readFile = "10.txt";
		state = read;
		break;
	case r15:
		readFile = "15.txt";
		state = read;
		break;
	case r20:
		readFile = "20.txt";
		state = read;
		break;
	case r2d:
		readFile = "2d.txt";
		state = read;
		break;
	case save:
		std::ofstream plik;
		std::ostringstream name, comment;
		int licznika = 0;
		double suum = 0;
		for (int f=0; f < numberOfAtoms; f++)
			for (int k=0; k < numberOfAtoms; k++){
				double odleglosc = atomTable[f].position().distanceFromVector(atomTable[k].position());
				if (odleglosc > 2e-10 && odleglosc < 3e-10){
					std::cout << odleglosc << std::endl;
					licznika++;
					suum += odleglosc;
				}
			}

		std::cout << "liczba sasiadow: "<< licznika << " suma: " << suum << " srednia: " << suum/licznika << std::endl;

		name << numberOfAtoms << "-" << algoEngine.steps << ".txt";
		comment << "# " << numberOfAtoms << " atoms" << std::endl << "# "
				<< algoEngine.steps << " steps" << std::endl << "# "
				<< algoEngine.lastChangeStep << " last change step" << std::endl
				<< "# " << (double) algoEngine.currentEnergy / elementaryCharge
				<< " eV" << std::endl;
		plik.open(name.str().c_str());
		plik << comment.str();
		for (int i = 0; i < numberOfAtoms; i++)
			plik << atomTable[i].position() << std::endl;
		plik.close();
		state = pause;
		break;
	}

	//if ((algoEngine.steps - algoEngine.lastChangeStep) > 20000)
	//	state = pause;

	//std::cout << atomTable[0].position() << "\t\t" << atomTable[1].position()
	//		<< std::endl;
	glutPostRedisplay();
	glutTimerFunc(1, update, 0);
}
Ejemplo n.º 25
0
HRESULT Application::Init(HINSTANCE hInstance, bool windowed) {
    g_debug << "Application Started \n";

    //Create Window Class
    WNDCLASS wc;
    memset(&wc, 0, sizeof(WNDCLASS));
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WndProc;
    wc.hInstance     = hInstance;
    wc.lpszClassName = "D3DWND";

    RECT rc = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
    AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);

    //Register Class and Create new Window
    RegisterClass(&wc);
    m_mainWindow = ::CreateWindow("D3DWND", "Character Animation with Direct3D: Example 6.3", WS_OVERLAPPEDWINDOW, 0, 0, rc.right - rc.left, rc.bottom - rc.top, 0, 0, hInstance, 0);
    SetCursor(NULL);
    ::ShowWindow(m_mainWindow, SW_SHOW);
    ::UpdateWindow(m_mainWindow);

    //Create IDirect3D9 Interface
    IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION);

    if (d3d9 == NULL) {
        g_debug << "Direct3DCreate9() - FAILED \n";
        return E_FAIL;
    }

    //Check that the Device supports what we need from it
    D3DCAPS9 caps;
    d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);

    //Check vertex & pixelshader versions
    if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) {
        g_debug << "Warning - Your graphic card does not support vertex and pixelshaders version 2.0 \n";
    }

    //Set D3DPRESENT_PARAMETERS
    m_present.BackBufferWidth            = WINDOW_WIDTH;
    m_present.BackBufferHeight           = WINDOW_HEIGHT;
    m_present.BackBufferFormat           = D3DFMT_A8R8G8B8;
    m_present.BackBufferCount            = 2;
    m_present.MultiSampleType            = D3DMULTISAMPLE_NONE;
    m_present.MultiSampleQuality         = 0;
    m_present.SwapEffect                 = D3DSWAPEFFECT_DISCARD;
    m_present.hDeviceWindow              = m_mainWindow;
    m_present.Windowed                   = windowed;
    m_present.EnableAutoDepthStencil     = true;
    m_present.AutoDepthStencilFormat     = D3DFMT_D24S8;
    m_present.Flags                      = 0;
    m_present.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    m_present.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

    //Hardware Vertex Processing
    int vp = 0;
    if ( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
        vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
    else vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

    //Create the IDirect3DDevice9
    if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_mainWindow, vp, &m_present, &g_pDevice))) {
        g_debug << "Failed to create IDirect3DDevice9 \n";
        return E_FAIL;
    }

    //Release IDirect3D9 interface
    d3d9->Release();

    //Load Application Specific resources here...
    D3DXCreateFont(g_pDevice, 20, 0, FW_BOLD, 1, false,
                   DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
                   DEFAULT_PITCH | FF_DONTCARE, "Arial", &g_pFont);

    //Create Sprite
    D3DXCreateSprite(g_pDevice, &g_pSprite);

    //Load Effect
    ID3DXBuffer *pErrorMsgs = NULL;
    HRESULT hRes = D3DXCreateEffectFromFile(g_pDevice, "resources/fx/lighting.fx", NULL, NULL, D3DXSHADER_DEBUG, NULL, &g_pEffect, &pErrorMsgs);

    if (FAILED(hRes) && (pErrorMsgs != NULL)) {      //Failed to create Effect
        g_debug << (char*)pErrorMsgs->GetBufferPointer() << "\n";
        return E_FAIL;
    }

    LoadParticleResources();
    physicsEngine.Init();

    m_deviceLost = false;

    return S_OK;
}
Ejemplo n.º 26
0
void MyWindow::Pstep() {
	for( std::vector<Object>::iterator it = objects.begin(); it != objects.end(); it++) {
		pe.Step(*it);
	}
}