Skip to content

Commit

Permalink
examples fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Mar 9, 2016
1 parent 251b210 commit f746933
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
18 changes: 8 additions & 10 deletions examples/cube.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Cube {
// forward decl
static void InitializeCube(Cube *cube);
static void UpdateCube(Cube *cube);
static void RotateCube(Cube *cube, float radians);
static void RotateCube(Cube *cube, float radians, vec3 axis);

// cube constructor
void
Expand Down Expand Up @@ -62,7 +62,7 @@ InitializeCube(Cube *cube) {
2, 3, 7, 2, 7, 6,
};

cube->position = vec3(1, 1, 1);
cube->position = vec3(0, 0, 0);
cube->faceslen = sizeof(faces) / sizeof(GLushort);
GLuint size = sizeof(vertices);

Expand Down Expand Up @@ -115,8 +115,8 @@ DrawCube(Cube *cube) {
}

void
RotateCube(Cube *cube, float radians) {
(void) mat4_rotate(cube->rotation, radians, cube->position);
RotateCube(Cube *cube, float radians, vec3 axis) {
(void) mat4_rotate(cube->rotation, radians, axis);
}

int
Expand All @@ -131,16 +131,14 @@ main(void) {
Camera camera;
Cube cube;

// params
const float radius = 10.0f;

// init
GL_CONTEXT_INIT();
program = CreateProgram("cube.v.glsl", "cube.f.glsl");
InitializeCamera(&camera, WINDOW_WIDTH, WINDOW_HEIGHT);
InitializeCube(&cube);

camera.target = cube.position;
// move camera behind cube
camera.position = vec3(1, 1, 1);

GL_RENDER({
const float time = glfwGetTime();
Expand All @@ -157,8 +155,8 @@ main(void) {
// update camera orientation
UpdateCamera(&camera);

// rotate cube at radians angle
RotateCube(&cube, radians);
// rotate cube at radians angle in opposite direction
RotateCube(&cube, radians, vec3_negate(rotation));

// render cube
DrawCube(&cube);
Expand Down
5 changes: 2 additions & 3 deletions examples/grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ main(void) {
InitializeGrid(&grid);

// configure camera
//camera.position.y = 1;
camera.target = vec3(1, 1, 1);
camera.fov = 45;
camera.position = vec3(1, 1, 1);
camera.fov = 25;

// bind current shader program
glisy_program_bind(&program);
Expand Down
11 changes: 5 additions & 6 deletions examples/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ UpdateCameraProjectionMatrix(Camera *camera) {

void
UpdateCameraLookAt(Camera *camera) {
vec3 target = vec3_transform_mat4(camera->target,
camera->transform);
camera->view = mat4_lookAt(target,
camera->position,
camera->up);
vec3 target = camera->target;
vec3 position = vec3_transform_mat4(camera->position,
camera->transform);
camera->view = mat4_lookAt(position, target, camera->up);
glisy_uniform_bind(&camera->uView, 0);
mat4_identity(camera->transform);
}
Expand Down Expand Up @@ -129,7 +128,7 @@ InitializeCamera(Camera *camera, int width, int height) {

camera->aspect = width / height;
camera->near = 1.0f;
camera->far = 100.0f;
camera->far = 1000.0f;
camera->fov = 45.0f;

mat4_identity(camera->projection);
Expand Down

0 comments on commit f746933

Please sign in to comment.