cam test
This commit is contained in:
@@ -20,7 +20,7 @@ void cameraInitPerspective(camera_t *camera) {
|
||||
camera->projType = CAMERA_PROJECTION_TYPE_PERSPECTIVE;
|
||||
camera->perspective.fov = glm_rad(45.0f);
|
||||
camera->nearClip = 0.1f;
|
||||
camera->farClip = 100.0f;
|
||||
camera->farClip = 10000.0f;
|
||||
|
||||
camera->viewType = CAMERA_VIEW_TYPE_LOOKAT;
|
||||
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_NULL, "Cannot have NULL entity type");
|
||||
|
||||
if(entity->type == ENTITY_TYPE_PLAYER) {
|
||||
playerMovement(entity);
|
||||
}
|
||||
|
||||
// Velocity
|
||||
for(uint8_t i = 0; i < WORLD_DIMENSIONS; i++) {
|
||||
if(entity->velocity[i] == 0) continue;
|
||||
|
@@ -17,16 +17,19 @@ void playerInit(entity_t *entity) {
|
||||
void playerMovement(entity_t *entity) {
|
||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||
|
||||
// // Update velocity.
|
||||
// vec2 dir = {
|
||||
// inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT),
|
||||
// inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP)
|
||||
// };
|
||||
// if(dir[0] == 0 && dir[1] == 0) return;
|
||||
// Get movement angle as 0-> normalized vector.
|
||||
{
|
||||
vec2 dir = {
|
||||
inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT),
|
||||
inputAxis(INPUT_ACTION_DOWN, INPUT_ACTION_UP)
|
||||
};
|
||||
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.
|
||||
// if(dir[0] > 0) {
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#define PLAYER_SPEED 64.0f
|
||||
#define PLAYER_SPEED 4
|
||||
#define PLAYER_INTERACTION_RANGE 1.0f
|
||||
#define PLAYER_INTERACTION_SIZE 0.5f
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "rpg.h"
|
||||
#include "entity/entity.h"
|
||||
#include "time/time.h"
|
||||
|
||||
errorret_t rpgInit(void) {
|
||||
// TEST
|
||||
@@ -20,6 +21,8 @@ errorret_t rpgInit(void) {
|
||||
}
|
||||
|
||||
void rpgUpdate(void) {
|
||||
if(!TIME.fixedUpdate) return;
|
||||
|
||||
entity_t *ent = &ENTITIES[0];
|
||||
do {
|
||||
if(ent->type == ENTITY_TYPE_NULL) continue;
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "display/spritebatch.h"
|
||||
#include "assert/assert.h"
|
||||
#include "rpg/entity/entity.h"
|
||||
#include "display/screen.h"
|
||||
|
||||
#define TILE_WIDTH 1
|
||||
#define TILE_HEIGHT TILE_WIDTH
|
||||
@@ -17,10 +18,6 @@
|
||||
errorret_t sceneMapInit(scenedata_t *data) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -28,6 +25,19 @@ void sceneMapUpdate(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);
|
||||
|
||||
entity_t *ent = ENTITIES;
|
||||
|
@@ -19,7 +19,7 @@ typedef struct {
|
||||
|
||||
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.
|
||||
|
Reference in New Issue
Block a user