~zjm/Moon3D

ref: 0fe31db4998f636b8f65ca790b75c0585ba47d86 Moon3D/src/player.c -rw-r--r-- 836 bytes
0fe31db4Zack Michener refactor camera/projection to avoid globals 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "player.h"
#include <stdlib.h>

Player *NewPlayer(Vertex position)
{
	Player *player = malloc(sizeof(Player));

	player->camera = NewCamera(position);
	LookAt(V(0, 0, 0), player->camera);

	return player;
}

void PlayerTurnLeft(Player *player, double angle)
{
	RotateCamera(0, angle, 0, player->camera);
}

void PlayerTurnRight(Player *player, double angle)
{
	RotateCamera(0, -angle, 0, player->camera);
}

void PlayerMoveForward(Player *player, double amount)
{
	MoveCamera(VecMul(player->camera->direction, amount), player->camera);
}

void PlayerMoveBackward(Player *player, double amount)
{
	MoveCamera(VecMul(player->camera->direction, -amount), player->camera);
}

Vector PlayerDirection(Player *player)
{
	return player->camera->direction;
}

Vertex PlayerPosition(Player *player)
{
	return player->camera->position;
}