cam test
This commit is contained in:
@@ -20,7 +20,7 @@ void cameraInitPerspective(camera_t *camera) {
|
|||||||
camera->projType = CAMERA_PROJECTION_TYPE_PERSPECTIVE;
|
camera->projType = CAMERA_PROJECTION_TYPE_PERSPECTIVE;
|
||||||
camera->perspective.fov = glm_rad(45.0f);
|
camera->perspective.fov = glm_rad(45.0f);
|
||||||
camera->nearClip = 0.1f;
|
camera->nearClip = 0.1f;
|
||||||
camera->farClip = 100.0f;
|
camera->farClip = 10000.0f;
|
||||||
|
|
||||||
camera->viewType = CAMERA_VIEW_TYPE_LOOKAT;
|
camera->viewType = CAMERA_VIEW_TYPE_LOOKAT;
|
||||||
glm_vec3_copy((vec3){ 5.0f, 5.0f, 5.0f }, camera->lookat.position);
|
glm_vec3_copy((vec3){ 5.0f, 5.0f, 5.0f }, camera->lookat.position);
|
||||||
|
@@ -46,6 +46,10 @@ void entityUpdate(entity_t *entity) {
|
|||||||
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Invalid entity type");
|
assertTrue(entity->type < ENTITY_TYPE_COUNT, "Invalid entity type");
|
||||||
assertTrue(entity->type != ENTITY_TYPE_NULL, "Cannot have NULL entity type");
|
assertTrue(entity->type != ENTITY_TYPE_NULL, "Cannot have NULL entity type");
|
||||||
|
|
||||||
|
if(entity->type == ENTITY_TYPE_PLAYER) {
|
||||||
|
playerMovement(entity);
|
||||||
|
}
|
||||||
|
|
||||||
// Velocity
|
// Velocity
|
||||||
for(uint8_t i = 0; i < WORLD_DIMENSIONS; i++) {
|
for(uint8_t i = 0; i < WORLD_DIMENSIONS; i++) {
|
||||||
if(entity->velocity[i] == 0) continue;
|
if(entity->velocity[i] == 0) continue;
|
||||||
|
@@ -17,17 +17,20 @@ void playerInit(entity_t *entity) {
|
|||||||
void playerMovement(entity_t *entity) {
|
void playerMovement(entity_t *entity) {
|
||||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||||
|
|
||||||
// // Update velocity.
|
// Get movement angle as 0-> normalized vector.
|
||||||
// vec2 dir = {
|
{
|
||||||
// inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT),
|
vec2 dir = {
|
||||||
// inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP)
|
inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT),
|
||||||
// };
|
inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP)
|
||||||
// if(dir[0] == 0 && dir[1] == 0) return;
|
};
|
||||||
|
if(dir[0] == 0 && dir[1] == 0) return;
|
||||||
|
glm_vec2_normalize(dir);
|
||||||
|
|
||||||
|
entity->velocity[0] += (worldsubtile_t)(PLAYER_SPEED * dir[0]);
|
||||||
|
entity->velocity[1] += (worldsubtile_t)(PLAYER_SPEED * dir[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// glm_vec2_normalize(dir);
|
|
||||||
// entity->velocity[0] += PLAYER_SPEED * dir[0];
|
|
||||||
// entity->velocity[1] += PLAYER_SPEED * dir[1];
|
|
||||||
|
|
||||||
// // Update direction.
|
// // Update direction.
|
||||||
// if(dir[0] > 0) {
|
// if(dir[0] > 0) {
|
||||||
// if(entity->direction == DIRECTION_RIGHT) {
|
// if(entity->direction == DIRECTION_RIGHT) {
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
#define PLAYER_SPEED 64.0f
|
#define PLAYER_SPEED 4
|
||||||
#define PLAYER_INTERACTION_RANGE 1.0f
|
#define PLAYER_INTERACTION_RANGE 1.0f
|
||||||
#define PLAYER_INTERACTION_SIZE 0.5f
|
#define PLAYER_INTERACTION_SIZE 0.5f
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "rpg.h"
|
#include "rpg.h"
|
||||||
#include "entity/entity.h"
|
#include "entity/entity.h"
|
||||||
|
#include "time/time.h"
|
||||||
|
|
||||||
errorret_t rpgInit(void) {
|
errorret_t rpgInit(void) {
|
||||||
// TEST
|
// TEST
|
||||||
@@ -20,6 +21,8 @@ errorret_t rpgInit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void rpgUpdate(void) {
|
void rpgUpdate(void) {
|
||||||
|
if(!TIME.fixedUpdate) return;
|
||||||
|
|
||||||
entity_t *ent = &ENTITIES[0];
|
entity_t *ent = &ENTITIES[0];
|
||||||
do {
|
do {
|
||||||
if(ent->type == ENTITY_TYPE_NULL) continue;
|
if(ent->type == ENTITY_TYPE_NULL) continue;
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "display/spritebatch.h"
|
#include "display/spritebatch.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
|
#include "display/screen.h"
|
||||||
|
|
||||||
#define TILE_WIDTH 1
|
#define TILE_WIDTH 1
|
||||||
#define TILE_HEIGHT TILE_WIDTH
|
#define TILE_HEIGHT TILE_WIDTH
|
||||||
@@ -17,10 +18,6 @@
|
|||||||
errorret_t sceneMapInit(scenedata_t *data) {
|
errorret_t sceneMapInit(scenedata_t *data) {
|
||||||
cameraInitPerspective(&data->sceneMap.camera);
|
cameraInitPerspective(&data->sceneMap.camera);
|
||||||
|
|
||||||
data->sceneMap.camera.lookat.position[0] = 3;
|
|
||||||
data->sceneMap.camera.lookat.position[1] = 3;
|
|
||||||
data->sceneMap.camera.lookat.position[2] = 3;
|
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +25,19 @@ void sceneMapUpdate(scenedata_t *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sceneMapRender(scenedata_t *data) {
|
void sceneMapRender(scenedata_t *data) {
|
||||||
|
const float_t camOffset = 12.0f;
|
||||||
|
const float_t pixelPerfectOffset = tanf(
|
||||||
|
data->sceneMap.camera.perspective.fov / 2.0f
|
||||||
|
) * ((float_t)SCREEN.height / 2.0f);
|
||||||
|
|
||||||
|
glm_vec3_copy((vec3){
|
||||||
|
data->sceneMap.camera.lookat.target[0],
|
||||||
|
data->sceneMap.camera.lookat.target[1] + camOffset,
|
||||||
|
data->sceneMap.camera.lookat.target[2] + pixelPerfectOffset
|
||||||
|
}, data->sceneMap.camera.lookat.position);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
cameraPushMatrix(&data->sceneMap.camera);
|
cameraPushMatrix(&data->sceneMap.camera);
|
||||||
|
|
||||||
entity_t *ent = ENTITIES;
|
entity_t *ent = ENTITIES;
|
||||||
|
@@ -19,7 +19,7 @@ typedef struct {
|
|||||||
|
|
||||||
extern dusktime_t TIME;
|
extern dusktime_t TIME;
|
||||||
|
|
||||||
#define TIME_STEP (1.0f / 60.0f) // Default to 60FPS
|
#define TIME_STEP (1.0f / 60.0f) // 60 Ticks per second.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the time system.
|
* Initializes the time system.
|
||||||
|
Reference in New Issue
Block a user