
Untitled
By: a guest on
Mar 16th, 2012 | syntax:
None | size: 2.23 KB | hits: 17 | expires: Never
/* camera.h */
#ifndef _CAMERA_H_
#define _CAMERA_H_
#include <psptypes.h>
/* ____________________ S T R U C T S ____________________ */
struct Camera
{
float x, y, z;
float pitch, yaw;
ScePspFMatrix4 matrix;
};
/* __________ P U B L I C F U N C T I O N S __________ */
void
updateCamera(float a_x, float a_y, float a_z, float a_pitch, float a_yaw);
ScePspFMatrix4
getCamMatrix(void);
#endif
/* camera.c */
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <pspgu.h>
#include <pspgum.h>
#include "camera.h"
static struct Camera camera;
void
updateCamera(float a_x, float a_y, float a_z, float a_pitch, float a_yaw)
{
camera.x = a_x;
camera.y = a_y;
camera.z = a_z;
camera.pitch = a_pitch;
camera.yaw = a_yaw;
/* update camera matrix */
ScePspFMatrix4 pitch, yaw, translate, result;
/* rotation about x-axis */
pitch.x.x = 1.0f;
pitch.x.y = 0.0f;
pitch.x.z = 0.0f;
pitch.x.w = 0.0f;
pitch.y.x = 0.0f;
pitch.y.y = cosf(camera.pitch);
pitch.y.z = -sinf(camera.pitch);
pitch.y.w = 0.0f;
pitch.z.x = 0.0f;
pitch.z.y = sinf(camera.pitch);
pitch.z.z = cosf(camera.pitch);
pitch.z.w = 0.0f;
pitch.w.x = 0.0f;
pitch.w.y = 0.0f;
pitch.w.z = 0.0f;
pitch.w.w = 1.0f;
/* rotation about y-axis */
yaw.x.x = cosf(camera.yaw);
yaw.x.y = 0.0f;
yaw.x.z = -sinf(camera.yaw);
yaw.x.w = 0.0f;
yaw.y.x = 0.0f;
yaw.y.y = 1.0f;
yaw.y.z = 0.0f;
yaw.y.w = 0.0f;
yaw.z.x = -sinf(camera.yaw);
yaw.z.y = 0.0f;
yaw.z.z = cosf(camera.yaw);
yaw.z.w = 0.0f;
yaw.w.x = 0.0f;
yaw.w.y = 0.0f;
yaw.w.z = 0.0f;
yaw.w.w = 1.0f;
gumMultMatrix(&result, &pitch, &yaw);
translate.x.x = 1.0f;
translate.x.y = 0.0f;
translate.x.z = 0.0f;
translate.x.w = 0.0f;
translate.y.x = 0.0f;
translate.y.y = 1.0f;
translate.y.z = 0.0f;
translate.y.w = 0.0f;
translate.z.x = 0.0f;
translate.z.y = 0.0f;
translate.z.z = 1.0f;
translate.z.w = 0.0f;
translate.w.x = camera.x;
translate.w.y = camera.y;
translate.w.z = camera.z;
translate.w.w = 1.0f;
gumMultMatrix(&result, &result, &translate);
gumLoadMatrix(&camera.matrix, &result);
}
ScePspFMatrix4
getCamMatrix(void)
{
return camera.matrix;
}