Esempio n. 1
0
///
//Translates the RenderingManager's camera according to keyboard input
//
//Parameters:
//	GO: The game object this state is attached to
//	state: the First Person Camera State updating the gameObject
void State_FirstPersonCamera_Translate(GObject* GO, State* state)
{
	Camera* cam = RenderingManager_GetRenderingBuffer().camera;

	if(InputManager_GetInputBuffer().mouseLock)
	{
		Vector netMvmtVec;
		Vector partialMvmtVec;
		Vector_INIT_ON_STACK(netMvmtVec, 3);
		Vector_INIT_ON_STACK(partialMvmtVec, 3);


		if (InputManager_IsKeyDown('w'))
		{
			//Get "back" Vector
			Matrix_SliceRow(&partialMvmtVec, cam->rotationMatrix, 2, 0, 3);
			//Subtract "back" Vector from netMvmtVec
			Vector_Decrement(&netMvmtVec, &partialMvmtVec);
			//Or in one step but less pretty... Faster though. I think I want readable here for now though.
			//Vector_DecrementArray(netMvmtVec.components, Matrix_Index(cam->rotationMatrix, 2, 0), 3);
		}
		if (InputManager_IsKeyDown('s'))
		{
			//Get "back" Vector
			Matrix_SliceRow(&partialMvmtVec, cam->rotationMatrix, 2, 0, 3);
			//Add "back" Vector to netMvmtVec
			Vector_Increment(&netMvmtVec, &partialMvmtVec);
		}
		if (InputManager_IsKeyDown('a'))
		{
			//Get "Right" Vector
			Matrix_SliceRow(&partialMvmtVec, cam->rotationMatrix, 0, 0, 3);
			//Subtract "Right" Vector From netMvmtVec
			Vector_Decrement(&netMvmtVec, &partialMvmtVec);
		}
		if (InputManager_IsKeyDown('d'))
		{
			//Get "Right" Vector
			Matrix_SliceRow(&partialMvmtVec, cam->rotationMatrix, 0, 0, 3);
			//Add "Right" Vector to netMvmtVec
			Vector_Increment(&netMvmtVec, &partialMvmtVec);
		}

		float dt = TimeManager_GetDeltaSec();

		if (Vector_GetMag(&netMvmtVec) > 0.0f && dt > 0.0f)
		{
			Vector_Normalize(&netMvmtVec);
			Vector_Scale(&netMvmtVec, state->members->movementSpeed * dt);

			Camera_Translate(cam, &netMvmtVec);
		}
	}

}
Esempio n. 2
0
///
//Updates the RenderManager's camera according to user input
//Moves, Rotates, and Skews the camera
//
//Parameters:
//	GO: The game object this state is attached to
//	state: The First person camera state updating the gameObject
void State_FirstPersonCamera_Update(GObject* GO, State* state)
{
	//printf("\nUpdating Cam\n");
	State_FirstPersonCamera_Rotate(GO, state);
	State_FirstPersonCamera_Translate(GO, state);
	State_FirstPersonCamera_Skew(GO, state);

		//Experimental feature
	if(InputManager_IsKeyDown('o'))
	{
		//Get Camera
		Camera* cam = RenderingManager_GetRenderingBuffer().camera;

		//Get the physics buffer
		PhysicsBuffer* buffer = PhysicsManager_GetPhysicsBuffer();

		//Get the global gravity force
		//Vector* gravity = (Vector*)buffer->globalForces->head->data;

		//Get z axis from camera
		//Vector zAxis;
		//Vector_INIT_ON_STACK(zAxis, 3);

		//Matrix_SliceRow(&zAxis, cam->rotationMatrix, 2, 0, 3);
		//Vector_Scale(&zAxis, -1.0f);

		//Vector_Copy(gravity, &zAxis);
	}

}
Esempio n. 3
0
///
//Skews the rendering manager's camera according to keyboard input
//
//Parameters:
//	GO: The game object this state is attached to
//	state: The First person camera state updating the gameObject
void State_FirstPersonCamera_Skew(GObject* GO, State* state)
{
	//TODO: Write Skew code here
	Camera* cam = RenderingManager_GetRenderingBuffer().camera;

	if(InputManager_IsKeyDown('='))
	{
		cam->nearPlane *= 1.001f;
		printf("Near Plane: %f\n", cam->nearPlane);
		Camera_RefreshPerspectiveMatrix(cam);
	}
	if(InputManager_IsKeyDown('-'))
	{
		cam->nearPlane *= 0.999f;
		printf("Far Plane: %f\n", cam->nearPlane);
		Camera_RefreshPerspectiveMatrix(cam);
	}

}
Esempio n. 4
0
///
//Updates a GObject using a Template state
//
//Parameters:
//	obj: A pointer to the GObject being updated
//	state: A pointer to the state updating the GObject
void State_ParkourController_Update(GObject* obj, State* state)
{
    //Get a reference to the state members
    struct State_ParkourController_Members* members = (struct State_ParkourController_Members*)state->members;


    //If it needs to be updated, update the shoot timer
    if(members->shootTimer < members->shootCooldown)
    {
        float dt = TimeManager_GetDeltaSec();
        members->shootTimer += dt;
    }
    //If the left mouse button is down, shoot
    if(InputManager_IsMouseButtonPressed(0))
    {
        State_ParkourController_Shoot(obj, state);
    }

    //Get a reference to the camera
    Camera* cam = RenderingManager_GetRenderingBuffer()->camera;

    //Determine if the object is colliding with anything
    if(obj->collider->currentCollisions->size > 0)
    {
        //Determine if the object is on the ground
        if(State_ParkourController_IsOnGround(obj))
        {
            //Allow the object to accelerate
            State_ParkourController_Accelerate(obj, state);
            if(InputManager_IsKeyDown(' '))
            {
                State_ParkourController_Jump(obj, state);
            }
        }

        //If the spacebar is being pressed even if the object is not on the floor
        if(InputManager_IsKeyDown(' '))
        {
            //Attempt to wallrun!
            State_ParkourController_Wallrun(obj, state);
        }
        else if(members->verticalRunning || members->horizontalRunning)
        {
            //Wall jump!
            State_ParkourController_WallJump(obj, state);

            //If vertically wallrunning, start spinning right round baby right round!
            if(members->verticalRunning) members->spinningTimer = 0.0f;

            //The object was wallrunning but now (s)he stopped before the wall ended
            members->verticalRunning = members->horizontalRunning = 0;
        }
    }
    else if(members->verticalRunning || members->horizontalRunning)
    {
        if(members->verticalRunning)
        {
            State_ParkourController_WallVault(obj, state);
        }

        //The character was wallrunning but now there is no wall
        members->verticalRunning = members->horizontalRunning = 0;
    }

    //If the parkour controller currently spinning off a wall, let it continue, else let the player rotate the controller
    if(members->spinningTimer < members->spinningTime)
    {
        float dt = TimeManager_GetDeltaSec();
        members->spinningTimer += dt;
        Camera_ChangeYaw(cam, spinningRate * dt);
    }
    else
    {
        //Allow the user to rotate the parkour controller
        State_ParkourController_Rotate(state);
    }

    //Set the position of the camera to match the object
    Camera_SetPosition(cam, obj->frameOfReference->position);
}
Esempio n. 5
0
///
//Accelerates a gameobject to the degree defined by the state
//
//PArameters:
//	obj: The gameobject to accelerate
//	state: The ParkourController state attached to the game object
static void State_ParkourController_Accelerate(GObject* obj, State* state)
{
    //Grab the state members
    struct State_ParkourController_Members* members = (struct State_ParkourController_Members*)state->members;

    //Grab the camera
    Camera* cam = RenderingManager_GetRenderingBuffer()->camera;

    //Determine the direction of acceleration
    Vector netForce;
    Vector_INIT_ON_STACK(netForce, 3);
    Vector direction;
    Vector_INIT_ON_STACK(direction, 3);
    if(InputManager_IsKeyDown('w'))
    {
        //Get forward vector of camera
        Matrix_SliceRow(&direction, cam->rotationMatrix, 2, 0, 3);
        //Project onto XY Plane
        Vector perp;
        Vector_INIT_ON_STACK(perp, 3);

        Vector_GetProjection(&perp, &direction, &Vector_E2);
        Vector_Decrement(&direction, &perp);

        //Add vector to netForce
        //Since this is the cameras "forward vector" we must add the negative of it.
        //BEcause forward is the negative Z axis
        Vector_Decrement(&netForce, &direction);
    }
    if(InputManager_IsKeyDown('s'))
    {
        //Get back vector of camera
        //Get forward vector of camera
        Matrix_SliceRow(&direction, cam->rotationMatrix, 2, 0, 3);
        //Project onto XY Plane
        Vector perp;
        Vector_INIT_ON_STACK(perp, 3);

        Vector_GetProjection(&perp, &direction, &Vector_E2);
        Vector_Decrement(&direction, &perp);

        //Add vector to netForce
        //Since this is the cameras "forward vector" we must add the negative of it.
        //BEcause forward is the negative Z axis
        Vector_Increment(&netForce, &direction);
    }
    if(InputManager_IsKeyDown('d'))
    {
        //Get forward vector of camera
        Matrix_SliceRow(&direction, cam->rotationMatrix, 0, 0, 3);
        //Project onto XY Plane
        Vector perp;
        Vector_INIT_ON_STACK(perp, 3);

        Vector_GetProjection(&perp, &direction, &Vector_E2);
        Vector_Decrement(&direction, &perp);

        //Add vector to netForce
        //Since this is the cameras "forward vector" we must add the negative of it.
        //BEcause forward is the negative Z axis
        Vector_Increment(&netForce, &direction);
    }
    if(InputManager_IsKeyDown('a'))
    {
        //Get forward vector of camera
        Matrix_SliceRow(&direction, cam->rotationMatrix, 0, 0, 3);
        //Project onto XY Plane
        Vector perp;
        Vector_INIT_ON_STACK(perp, 3);

        Vector_GetProjection(&perp, &direction, &Vector_E2);
        Vector_Decrement(&direction, &perp);

        //Add vector to netForce
        //Since this is the cameras "forward vector" we must add the negative of it.
        //BEcause forward is the negative Z axis
        Vector_Decrement(&netForce, &direction);
    }

    //Scale netforce to the acceleration magnitude
    Vector_Normalize(&netForce);
    Vector_Scale(&netForce, members->acceleration);

    //Only apply impulse if velocity is less than max speed
    if(Vector_GetMag(obj->body->velocity) < members->maxVelocity)
    {
        //Apply the impulse
        RigidBody_ApplyForce(obj->body, &netForce, &Vector_ZERO);
    }
    else
    {
        //Limit velocity
        Vector_Normalize(obj->body->velocity);
        Vector_Scale(obj->body->velocity, members->maxVelocity);
    }
}
// translate the character and his bounding box.
// Parameters:
//   GO: The game object this state is attached to (Used for translating the bounding box)
//   state: The first person camera state updating the gameObject
void State_CharacterController_Translate(GObject* GO, State* state)
{
	Camera* cam = RenderingManager_GetRenderingBuffer()->camera;
	//Get members
	struct State_CharacterController_Members* members = (struct State_CharacterController_Members*)state->members;

	if(InputManager_GetInputBuffer().mouseLock)
	{

		// Gets the time per second
		float dt = TimeManager_GetDeltaSec();
		Vector netMvmtVec;
		Vector partialMvmtVec;
		Vector_INIT_ON_STACK(netMvmtVec, 3);
		Vector_INIT_ON_STACK(partialMvmtVec, 3);


		if (InputManager_IsKeyDown('w'))
		{
			//Get "back" Vector
			Matrix_SliceRow(&partialMvmtVec, cam->rotationMatrix, 2, 0, 3);
			//Subtract "back" Vector from netMvmtVec
			Vector_Decrement(&netMvmtVec, &partialMvmtVec);
			//Or in one step but less pretty... Faster though. I think I want readable here for now though.
			//Vector_DecrementArray(netMvmtVec.components, Matrix_Index(cam->rotationMatrix, 2, 0), 3);
		}
		if (InputManager_IsKeyDown('s'))
		{
			//Get "back" Vector
			Matrix_SliceRow(&partialMvmtVec, cam->rotationMatrix, 2, 0, 3);
			//Add "back" Vector to netMvmtVec
			Vector_Increment(&netMvmtVec, &partialMvmtVec);
		}
		if (InputManager_IsKeyDown('a'))
		{
			//Get "Right" Vector
			Matrix_SliceRow(&partialMvmtVec, cam->rotationMatrix, 0, 0, 3);
			//Subtract "Right" Vector From netMvmtVec
			Vector_Decrement(&netMvmtVec, &partialMvmtVec);
		}
		if (InputManager_IsKeyDown('d'))
		{
			//Get "Right" Vector
			Matrix_SliceRow(&partialMvmtVec, cam->rotationMatrix, 0, 0, 3);
			//Add "Right" Vector to netMvmtVec
			Vector_Increment(&netMvmtVec, &partialMvmtVec);
		}


		if (Vector_GetMag(&netMvmtVec) > 0.0f)
		{
			// Get the projection and keep player grounded
			Vector perpMvmtVec;
			Vector_INIT_ON_STACK(perpMvmtVec, 3);
			Vector_GetProjection(&perpMvmtVec, &netMvmtVec, &Vector_E2);
			Vector_Decrement(&netMvmtVec, &perpMvmtVec);

			// Normalize vector and scale
			Vector_Normalize(&netMvmtVec);
			Vector_Scale(&netMvmtVec, members->movementSpeed);

			//Apply Impulse
			RigidBody_ApplyImpulse(GO->body, &netMvmtVec, &Vector_ZERO);


		}

	}

	// If vector is going too fast, the maxspeed will keep it from going faster, by scaling it by maxspeed.
	if(Vector_GetMag(GO->body->velocity) >= members->maxSpeed)
	{
		Vector_Normalize(GO->body->velocity);
		Vector_Scale(GO->body->velocity,members->maxSpeed);
	}

	// Set position of Camera to the body
	Camera_SetPosition(cam,GO->body->frame->position);
}