polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit fbd0007a1e3cede28d71dd1939595a44632caf6d
parent 6a1950cefd947d9d81eb71fca6a3eebe2b776f79
Author: William Casarin <jb55@jb55.com>
Date:   Tue,  6 Nov 2018 14:25:55 -0800

Merge branch 'master' into orbit-camera

Diffstat:
Metc/shaders/profile | 2+-
Msrc/main.c | 4++--
Msrc/orbit.c | 21++-------------------
Msrc/orbit.h | 13++++++++++---
Msrc/quat.h | 1+
5 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/etc/shaders/profile b/etc/shaders/profile @@ -1,3 +1,3 @@ -#version 320 es +#version 300 es precision mediump float; diff --git a/src/main.c b/src/main.c @@ -38,8 +38,8 @@ int main(void) SDL_Init( SDL_INIT_VIDEO ); /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */ - /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); */ - /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); */ + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); diff --git a/src/orbit.c b/src/orbit.c @@ -2,16 +2,12 @@ #include "orbit.h" #include "node.h" #include "vec3.h" +#include "quat.h" #include <math.h> void orbit_to_mat4(struct orbit *orbit, float *m) { -} - - -static void orbit_to_vec3(struct orbit *orbit, float *v3) -{ - /* float x = r * sin(theta) * cos(phi); */ + quat_axis_angle(orbit->angles.ypr) } /* static void orbit_update_node(struct node *node) { */ @@ -23,16 +19,3 @@ void orbit_to_node(struct orbit *orbit, struct node *node) { } -static void arcball_vector(int screen_width, int screen_height, int x, int y, float *p) -{ - p[0] = x/screen_width*2.0 - 1.0; - p[1] = -y/screen_height*2.0 - 1.0; - p[2] = 0.0; - - float xy_sq = p[0]*p[0] + p[1]*p[1]; - if (xy_sq < 1.0) - p[2] = sqrt(-xy_sq); - else - vec3_normalize(p, p); -} - diff --git a/src/orbit.h b/src/orbit.h @@ -5,9 +5,16 @@ struct node; struct orbit { - float radius; - float inclination; - float azimuth; + float dist; + union { + struct { + float yaw; + float pitch; + float roll; + }; + + float ypr[3]; + } angles; }; diff --git a/src/quat.h b/src/quat.h @@ -9,6 +9,7 @@ typedef float quat; void quat_id(quat *dest); void quat_multiply(quat *a, quat *b, quat *dest); void quat_axis_angle(float *axis, float angle, quat *dest); +void quat_from_axes(float yaw, float pitch, float roll); void quat_to_mat3(quat *quat, float *dest); void quat_multiply_vec3(quat *quat, float *vec, float *dest); quat *quat_inverse(quat *q, quat *dest);