-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
238 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include "camera.h" | ||
|
||
w_camera *create_camera(float x, float y) { | ||
w_camera *camera = malloc(sizeof(w_camera)); | ||
if (camera == NULL) { | ||
LOG("failed to allocate memory for camera"); | ||
return NULL; | ||
} | ||
memset(camera, 0, sizeof(w_camera)); | ||
camera->matrix = malloc(sizeof(float) * 16); | ||
if (camera->matrix == NULL) { | ||
LOG("failed to allocate memory for camera matrix"); | ||
free(camera); | ||
return NULL; | ||
} | ||
|
||
Matrix m = MatrixTranslate(-x, -y, 0); | ||
camera->matrix[0] = m.m0; | ||
camera->matrix[1] = m.m1; | ||
camera->matrix[2] = m.m2; | ||
camera->matrix[3] = m.m3; | ||
camera->matrix[4] = m.m4; | ||
camera->matrix[5] = m.m5; | ||
camera->matrix[6] = m.m6; | ||
camera->matrix[7] = m.m7; | ||
camera->matrix[8] = m.m8; | ||
camera->matrix[9] = m.m9; | ||
camera->matrix[10] = m.m10; | ||
camera->matrix[11] = m.m11; | ||
camera->matrix[12] = m.m12; | ||
camera->matrix[13] = m.m13; | ||
camera->matrix[14] = m.m14; | ||
camera->matrix[15] = m.m15; | ||
|
||
return camera; | ||
} | ||
void destroy_camera(w_camera *camera) { | ||
if (camera == NULL) { | ||
LOG("camera (null) already destroyed"); | ||
return; | ||
} | ||
sfree(camera->matrix); | ||
free(camera); | ||
} | ||
void add_camera_vec(w_camera *camera, Vector2 vec) { | ||
camera_x(camera) -= vec.x; | ||
camera_y(camera) -= vec.y; | ||
} | ||
void set_camera_vec(w_camera *camera, Vector2 vec) { | ||
camera_x(camera) = -vec.x; | ||
camera_y(camera) = -vec.y; | ||
} | ||
void set_camera_center(w_camera *camera, Vector2 vec) { | ||
camera_x(camera) = -vec.x + RENDER_W / 2; | ||
camera_y(camera) = -vec.y + RENDER_H / 2; | ||
} | ||
Vector2 get_camera_vec(w_camera *camera) { | ||
return VEC(-camera_x(camera), -camera_y(camera)); | ||
} | ||
Vector2 get_camera_center(w_camera *camera) { | ||
return VEC(-camera_x(camera) + RENDER_W / 2, | ||
-camera_y(camera) + RENDER_H / 2); | ||
} | ||
Vector2 get_camera_object_center(w_camera *camera, Rectangle object) { | ||
return VEC(-camera_x(camera) + object.x + (RENDER_W - object.width) / 2, | ||
-camera_y(camera) + object.y + (RENDER_H - object.height) / 2); | ||
} | ||
Rectangle get_camera_view(w_camera *camera) { | ||
return RECT(-camera_x(camera), -camera_y(camera), RENDER_W, RENDER_H); | ||
} | ||
Rectangle get_camera_view_with_gap(w_camera *camera) { | ||
return RECT(-camera_x(camera) - RENDER_CUBE_GAP * CUBE_W, | ||
-camera_y(camera) - RENDER_CUBE_GAP * CUBE_H, | ||
RENDER_W + RENDER_CUBE_GAP * CUBE_W * 2, | ||
RENDER_H + RENDER_CUBE_GAP * CUBE_H * 2); | ||
} | ||
void begin_camera(w_camera *camera) { | ||
rlDrawRenderBatchActive(); | ||
rlLoadIdentity(); | ||
rlMultMatrixf(camera->matrix); | ||
} | ||
void end_camera() { | ||
rlDrawRenderBatchActive(); | ||
rlLoadIdentity(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include "../../stdafx.h" | ||
|
||
#define camera_x(camera) (camera->matrix[12]) | ||
#define camera_y(camera) (camera->matrix[13]) | ||
|
||
typedef struct w_camera { | ||
float *matrix; | ||
} w_camera; | ||
|
||
w_camera *create_camera(float x, float y); | ||
void destroy_camera(w_camera *camera); | ||
|
||
void add_camera_vec(w_camera *camera, Vector2 vec); | ||
void set_camera_vec(w_camera *camera, Vector2 vec); | ||
void set_camera_center(w_camera *camera, Vector2 vec); | ||
|
||
Vector2 get_camera_vec(w_camera *camera); | ||
Vector2 get_camera_center(w_camera *camera); | ||
|
||
Rectangle get_camera_view(w_camera *camera); | ||
Rectangle get_camera_view_with_gap(w_camera *camera); | ||
|
||
void begin_camera(w_camera *camera); | ||
void end_camera(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "smooth.h" | ||
|
||
void smooth_vec(Vector2 *position, Vector2 target, float move) { | ||
smooth_float(position->x, target.x, move); | ||
smooth_float(position->y, target.y, move); | ||
} | ||
|
||
void smooth_rect(Rectangle *box, Rectangle target, float move) { | ||
smooth_float(box->x, target.x, move); | ||
smooth_float(box->y, target.y, move); | ||
} | ||
void smooth_camera(w_camera *camera, Vector2 target, float move) { | ||
smooth_float(camera_x(camera), -target.x, move); | ||
smooth_float(camera_y(camera), -target.y, move); | ||
} | ||
Vector2 vec_block_round(Vector2 vec) { | ||
return VEC(roundf(vec.x / (float)CUBE_W) * (float)CUBE_W, | ||
roundf(vec.y / (float)CUBE_H) * (float)CUBE_H); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
#include "../../stdafx.h" | ||
#include "camera.h" | ||
|
||
#define smooth_float(current, target, speed) \ | ||
current = ((float)current < (float)target) \ | ||
? fmin((float)current + (float)speed, (float)target) \ | ||
: fmax((float)current - (float)speed, (float)target); | ||
|
||
void smooth_vec(Vector2 *position, Vector2 target, float move); | ||
void smooth_rect(Rectangle *box, Rectangle target, float move); | ||
void smooth_camera(w_camera *camera, Vector2 target, float move); | ||
|
||
Vector2 vec_block_round(Vector2 vec); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#pragma once | ||
#include "../core/view.h" | ||
#include "../core/controls.h" | ||
#include "../stdafx.h" | ||
#include "gui.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#pragma once | ||
#include "../core/view.h" | ||
#include "../core/controls.h" | ||
#include "../stdafx.h" | ||
#include "gui.h" | ||
|
Oops, something went wrong.