void CEngine::CreateSystems()
{
    AddSystem( Input() );
    AddSystem( Sound() );
	AddSystem( Physics() );
	AddSystem( Script() );	
}
//-----------------------------------------------------------------------------
// Exports IPhysics.
//-----------------------------------------------------------------------------
void export_physics(scope _physics)
{
	class_<IPhysicsWrapper, boost::noncopyable> Physics("Physics", no_init);

	Physics.def(
		"get_active_environment_by_index",
		&IPhysicsWrapper::GetActiveEnvironmentByIndex,
		manage_new_object_policy()
	);

	//Physics ADD_MEM_TOOLS_WRAPPER(IPhysicsWrapper, IPhysics);

	_physics.attr("physics") = object(ptr(Wrap<IPhysicsWrapper>(physics)));
}
Beispiel #3
0
void TauWindow::paintGL() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	/*glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	blob1->Render();
	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
	blob2->Render();*/
	QVector<IGameObject *> tmp = Physics()->m_vObjects;
	for (int i = 0; i < tmp.size(); i++) {
		tmp[i]->Render();
	}

	RenderFps();

	glFlush();
	glFinish();
	swapBuffers();
}
void CPongPlayer::Init( bool topdown, float width, float thickness, 
						float x, float y, float movespeed, 
						int key_minus, int key_plus )
{
	m_bTopdown = topdown;

	m_flMovespeed = movespeed;

	m_iKeyMinus = key_minus;
	m_iKeyPlus = key_plus;
		
    b2BodyDef def;
	b2PolygonShape shape;
	shape.SetAsBox( 0.5f*width, 0.5f*thickness, b2Vec2(0.0f, 0.0f), topdown ? b2_pi/2 : 0.0f);
		
	b2Vec2 pos(x, y);
	def.position = pos;
	def.type = b2_dynamicBody;
	def.fixedRotation = true;
	def.userData = this;
		
	m_pBody = Physics()->CreateBody(&shape, &def);		
}
Beispiel #5
0
void 
World::Think(float time)
{
	const float RADIANS_PER_SECOND = 0.5;
	
	Physics(time);

	// Move right paddle up
	if (mInputHandler->IsKeyDown(OIS::KC_UP))
	{
		if (mRightPaddleNode->getPosition().y <= 35.3) // Don't go past top wall
			mRightPaddleNode->translate(0, time * ballSpeed, 0);
	}

	// Move right paddle down
	else if (mInputHandler->IsKeyDown(OIS::KC_DOWN))
	{
		if (mRightPaddleNode->getPosition().y >= -36) // Don't go past bottom wall
			mRightPaddleNode->translate(0, -time * ballSpeed, 0);
	}

	updateScoreboard();
}
ArbitraryAI::ArbitraryAI(const std::string& name, Camera* cameraInstance, const int& radius) : SimpleMeshObject(name) {

	camera = cameraInstance; //i kept in the camera pointer as i imagine most of our AI's will use camera position eventually 

	//Next lines create the physical and graphical representation of the object you want your AI to be (just like for any other GameObject

	SetMesh(AssetsManager::Sphere(), false);
	SetLocalTransform(Matrix4::Scale(Vector3(0.3f, 0.3f, 0.3f)));
	SetColour(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
	SetBoundingRadius(1.0f);
	Physics()->SetInverseMass(1.0f);
	Physics()->SetForce(Vector3(0.0f, 9.81f, 0.0f));
	Physics()->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
	Physics()->SetCollisionShape(new SphereCollisionShape(0.3f));
	Physics()->SetInverseInertia(Physics()->GetCollisionShape()->BuildInverseInertia(1.0f));

	//1 == home state, 2 == guard state

	currentState = new OffState(); //sets the initial current state for the first frame (actually instantiates the state when the state is changed, so you dont have inactive states instantiated and sitting in memory doing nothing, ie rather than creating all states at startup and just changing the pointed, create and delkete states as they are used
}
Beispiel #7
0
//All objects have types, when a certain type is located in the entities vector,
//appropriate actions are taken
//The process for each entity object is very similar, except that sometimes some tings 
//are not assigned for certain entities since they don't need them
void GameInit::createMeshes(Shader* s, Shader* os) {

	for (int i = 0; i < entities.size(); ++i) {
		if (entities[i]->getObjectType() == WHITE_BALL || entities[i]->getObjectType() == BALL || entities[i]->getObjectType() == RED_BALL) {
			//Create the physical representation for this object
			entities[i]->setPhysObject(Physics(entities[i]->getPosition(), 1.0f, PX_BALL));
			//create a mesh for this object
			arrayOfMeshes[i] = Mesh::GenerateCircle(entities[i]->getPosition(), entities[i]->getColour(), entities[i]->getRadius());
			//Create a render object for this object
			entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], os));
			
			//The thing is that all objects are initially created at (0,0,0) and then reallocated into their own intended positions.
			//This is done to ensure that the positions of the entities and their physics is the same as the positions of their
			//respective rendered objects on the screen
			
			//So first translate the render object to the intended position on the screen
			entities[i]->getRenderObject().SetModelMatrix(Matrix4::Translation(colouredBallPos[i]) * Matrix4::Scale(Vector3(1, 1, 1)));
			//Then set the position of the entity object
			entities[i]->setPosition(colouredBallPos[i]);
			//Every entity however has an original (intended) position variable within them
			//this is so that when balls are potted into the pockets, I could easily access the 
			//intended positions of each object individually and set the current positions of the 
			//objects to the intended ones.
			entities[i]->setOriginalPosition(colouredBallPos[i]);
			//Set the physics of each entity to the intended position on the screen
			entities[i]->getPhysObject().setPhysPosition(colouredBallPos[i]);
		}
		if (entities[i]->getObjectType() == ARROW) {
			arrayOfMeshes[i] = Mesh::GenerateArrow(entities[i]->getPosition(), entities[i]->getPosition2());
			entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], s));
			entities[i]->getRenderObject().SetModelMatrix(Matrix4::Translation(whiteBallPosition) * Matrix4::Scale(Vector3(1, 1, 1)));
			entities[i]->setPosition(whiteBallPosition);
		}
		if (entities[i]->getObjectType() == POCKET) {
			for (int j = k; j < pocketIndecies.size(); j++) {
				entities[i]->setPhysObject(Physics(entities[i]->getPosition(), 1.0f, PX_POCKET));
				arrayOfMeshes[i] = Mesh::GenerateCircle(entities[i]->getPosition(), entities[i]->getColour(), entities[i]->getRadius());
				entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], s));
				entities[i]->getRenderObject().SetModelMatrix(Matrix4::Translation(pocketIndecies[k]) * Matrix4::Scale(Vector3(1, 1, 1)));
				entities[i]->setPosition(pocketIndecies[k]);
				entities[i]->getPhysObject().setPhysPosition(pocketIndecies[k]);
				break;
			}
			k++;
		}
		if (entities[i]->getObjectType() == LINE) {
			arrayOfMeshes[i] = Mesh::GenerateLine(entities[i]->getPosition(), entities[i]->getPosition2());
			entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], s));
		}
		if (entities[i]->getObjectType() == HALF_CIRCLE) {
			arrayOfMeshes[i] = Mesh::GenerateHalfCircle(entities[i]->getPosition(), entities[i]->getColour(), entities[i]->getRadius());
			entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], s));
		}
		if (entities[i]->getObjectType() == SPOT) {
			arrayOfMeshes[i] = Mesh::GeneratePoints(entities[i]->getPosition());
			entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], s));
		}
		if (entities[i]->getObjectType() == TABLE) {
			entities[i]->setPhysObject(Physics(entities[i]->getPosition(), PX_TABLE));
			arrayOfMeshes[i] = Mesh::GenerateTriangleStrip(entities[i]->getColour(), entities[i]->getColour(), entities[i]->getColour(), tableIndecies);
			entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], s));
			if (entities[i]->getColour() == TABLE_BROWN)
				entities[i]->getRenderObject().SetModelMatrix(Matrix4::Scale(Vector3(1.05f, 1.1f, 1.0f)));
		}
		if (entities[i]->getObjectType() == POW_BAR) {
			if (entities[i]->getColour() == TABLE_GREEN) {
				entities[i]->setPosition(Vector3(0.0f, -1.7f, -3.0f));
				entities[i]->setPhysObject(Physics(entities[i]->getPosition(), PX_TABLE));
				entities[i]->getPhysObject().setPhysPosition(entities[i]->getPosition());
				arrayOfMeshes[i] = Mesh::GenerateTriangleStrip(GREEN, YELLOW, RED, tableIndecies);
				entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], s));
				entities[i]->getRenderObject().SetModelMatrix(Matrix4::Translation(Vector3(0.0f, -1.7f, -3.0f)) * Matrix4::Scale(Vector3(1.5f, 0.2f, 1.0f)));
			}
			if (entities[i]->getColour() == GREY) {
				entities[i]->setPhysObject(Physics(entities[i]->getPosition(), PX_TABLE));
				arrayOfMeshes[i] = Mesh::GenerateTriangleStrip(entities[i]->getColour(), entities[i]->getColour(), entities[i]->getColour(), tableIndecies);
				entities[i]->setRenderObject(RenderObject(arrayOfMeshes[i], s));
				entities[i]->getRenderObject().SetModelMatrix(Matrix4::Translation(Vector3(-1.5f, -1.7f, -3.0f)) * Matrix4::Scale(Vector3(0.02f, 0.3f, 1.0f)));
				entities[i]->setPosition(Vector3(-1.5f, -1.7f, -3.0f));
				entities[i]->getPhysObject().setPhysPosition(entities[i]->getPosition());
			}
		}
	}
	if (s->UsingDefaultShader()) {
		cout << "Warning: Using default shader! Your shader probably hasn't worked..." << endl;
		cout << "Press any key to continue." << endl;
		std::cin.get();
	}
}
Beispiel #8
0
SwimScene::SwimScene( Game* game) : Scene(game)
{
    nextScene = NULL;
    alertButton = QRect( 260, 270, 120, 100 );
    lastKey = Qt::Key_unknown;
    timer.start();
    elapsedTime = 0;

    if( getGameClass()->getGamemode() == SINGLE )
        numOfPlayers = 1;
    else
        numOfPlayers = 4;

    player = new Character [numOfPlayers];
    swimFactor = new double[numOfPlayers];
    swimmerShapeCount = new int[numOfPlayers];
    position = new double[numOfPlayers];
    characterImgName = new QByteArray[numOfPlayers];

    switch( getGameClass()->getCharacterInUse() ) {
    case POBBA:
        player[0] = Pobba();
        characterImgName[0] = "pobba_swim";
        break;
    case KAISER:
        player[0] = Kaiser();
        characterImgName[0] = "kaiser_swim";
        break;
    case SWIMMER:
        player[0] = Swimmer();
        characterImgName[0] = "swimmer_swim";
        break;
    case PHYSICS:
        player[0] = Physics();
        characterImgName[0] = "physics_swim";
        break;
    case DEPTTOP:
        player[0] = Depttop();
        characterImgName[0] = "deptTop_swim";
        break;
    case STUDENT:
    default:
        player[0] = Character();
        characterImgName[0] = "default_swim";
        break;
    }
    if( getGameClass()->getGamemode() == OLYMPIC ) {
        player[1] = Kaist();
        characterImgName[1] = "kaist_swim";
        player[2] = Unist();
        characterImgName[2] = "unist_swim";
        player[3] = Gist();
        characterImgName[3] = "gist_swim";
    }

    for(int i=0; i<numOfPlayers; i++) {
        swimFactor[i] = player[i].getSpeed();
    }
    if( getGameClass()->getCharacterInUse() == SWIMMER )
        swimFactor[0] *= 4.5;
    else
        swimFactor[0] *= 3.0;

    if (getGameClass()->getGamemode() == SINGLE)
        diff = getGameClass()->getSingleDifficulty();
    else
        diff = getGameClass()->getOlympicDifficulty();

    switch( diff ) {
    case EASY:
        for(int i=1; i<numOfPlayers; i++)
            swimFactor[i] *= 0.8;
        break;
    case NORMAL:
    default:
        for(int i=1; i<numOfPlayers; i++)
            swimFactor[i] *= 1.0;
        break;
    case HARD:
        for(int i=1; i<numOfPlayers; i++)
            swimFactor[i] *= 1.2;
        break;
    }

    for(int i=0; i<numOfPlayers; i++) {
        position[i] = 0.0;
        swimmerShapeCount[i] = i;
    }
    finishPosition = 580.0;
    userSwimCount = 0;
    opponentSwimCount = 0;

    finishedPlayerCount = 0;
    for(int i=0; i<4; i++)
        score[i] = 0;
}
Beispiel #9
0
#include "StdAfx.h"
#include "Enemy.h"

Enemy::Enemy(float x, float y, Ball^ b)
{
    physics = gcnew Physics();

    xPos = x;
    yPos = y;
    width = SIZEX;
    height = SIZEY;

    ball = b;
}

void Enemy::update()
{
    if (physics->checkCollision(this, ball)) ball->reverseX(getCenterY());

    float speed = (ball->getCenterY() - getCenterY()) * DAMPING;

    if (speed > MAX_SPEEDY) speed = MAX_SPEEDY;
    if (speed < -MAX_SPEEDY) speed = -MAX_SPEEDY;

    yPos += speed;
}
Beispiel #10
0
void Physics::damagePlayerHull( float velocity, Player& player ) {
    if( velocity >= HULL_DAMAGE_THRESHOLD ) {
        player.damageHull( (int) ( velocity * HULL_DAMAGE_SCALER ) );
    } else if( velocity <= -HULL_DAMAGE_THRESHOLD ) {
        player.damageHull( (int) ( -velocity * HULL_DAMAGE_SCALER ) );
    }
}

void Physics::reset() {
    velocity.x = 0;
    velocity.y = 0;
}

Physics& Physics::getPhysics(){ return singleton; }

Physics Physics::singleton = Physics();

const float Physics::GRAVITY_STRENGTH = 0.003f;
const float Physics::PLAYER_MASS = 1.0f;
const float Physics::HORIZONTAL_AIR_RESISTANCE = 0.05f;
const float Physics::VERTICAL_AIR_RESISTANCE = 0.001f;
const float Physics::MINIMUM_VELOCITY = 0.01f;
const float Physics::BOUNCE_FACTOR = 0.2f;
const float Physics::PLAYER_MAX_SPEED = 0.2f;
const float Physics::HULL_DAMAGE_THRESHOLD = 0.028f;
const float Physics::HULL_DAMAGE_SCALER = 1000.0f;

Physics::Physics(void){
    previousLocation = sf::Vector2f(1.0f,1.0f);
}
Beispiel #11
0
int main()
{
	GLFWwindow* window = nullptr;

	glfwSetErrorCallback(error_callback);

	// Inititiating GLFW library
	if (!glfwInit()) 
		exit(EXIT_FAILURE);

	// Sets hints for the next call to glfwCreateWindow - Keep these for future debugging
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
	glfwWindowHint(GLFW_REFRESH_RATE, GLFW_DONT_CARE);// This hint is ignored for windowed mode windows.

	// Creating window
	window = glfwCreateWindow(640, 480, "Title", NULL, NULL);

	// Failure check - Creating window
	if (!window)
	{
		glfwTerminate();
		exit(EXIT_FAILURE);
	}
	else
	{
		fprintf(stderr, "GLFW Window initialized\n");
	}

	// Bind key-inputs
	glfwSetKeyCallback(window, key_callback);

	// Fetch OpenGL version - Makes sure correct version is loaded from GLEW
	glfwMakeContextCurrent(window);
	// Inititiating GLEW library
	glewExperimental = true;
	GLenum err = glewInit();

	// Failure check - Inititiating GLEW
	if (GLEW_OK != err)
	{
		fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
	}
	else
	{
		fprintf(stderr, "GLEW initialized\n");
	}

#ifdef _DEBUG
	if (glDebugMessageCallback){
		std::cout << "Register OpenGL debug callback " << std::endl;
		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
		glDebugMessageCallback((GLDEBUGPROC)openglCallbackFunction, nullptr);
		GLuint unusedIds = 0;
		glDebugMessageControl(GL_DONT_CARE,
			GL_DONT_CARE,
			GL_DONT_CARE,
			0,
			&unusedIds,
			true);
	}
	else
	{
		std::cout << "glDebugMessageCallback not available" << std::endl;
	}
#endif

	// VSync
	glfwSwapInterval(1);

	////////////////////////////////////////////////////////////

	// Engine classes
	Graphics ge = Graphics();
	Physics ph = Physics();

	InitMeshes(&ge);

	InitCameras();
	ge.SetCamera(&cameras[cameraIndex]);
	
	fpsCounter fpsC;
	int tickCounter = 400;
	////////////////////////////////////////////////////////////
	while (!glfwWindowShouldClose(window))
	{
		std::stringstream ss;
		ss << fpsC.get();

		glfwSetWindowTitle(window, ss.str().c_str());

		KeyEvents(window, &ge, &ph);

		UpdateProjections(window);
		RotateCamera(&cameras[cameraIndex], window);
		MoveCamera(&cameras[cameraIndex], window);

		if (fpsC.deltaTime() > 0 && tickCounter < 1)
		{
			//ph.move(&mustangHigh, &fpsC);
			ph.move(&EndOfLine, &fpsC);
		}
		else
		{
			tickCounter--;
		}

		Collision(&EndOfLine, &target);
		Collision(&EndOfLine, &target2);

		ge.PrepareRender();
		ge.Render(&mustang);
		ge.Render(&mustang2);
		ge.Render(&mustang3);
		ge.Render(&mustang4);
		ge.Render(&mustangHigh);

		ge.Render(&ground);
		ge.Render(&target);
		ge.Render(&target2);

		ge.Render(&EndOfLine);

		fpsC.tick();
		Sleep(1000 / 120);

		glfwSwapBuffers(window);
		glfwPollEvents();// Processes all pending events
	}
	////////////////////////////////////////////////////////////
	
	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}