summaryrefslogtreecommitdiff
path: root/kmscube
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2020-10-07 08:58:35 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2020-10-09 15:54:43 +0300
commitd9a1ffe56d0beb9cdd048d0e83f7d0177b31411a (patch)
tree6227b71ee23bfa344b4cd5896ec485409158a0bc /kmscube
parent37d27443432b7b84d256bd5a7c505e7ef8e09bbd (diff)
Bulk format of all files
Diffstat (limited to 'kmscube')
-rw-r--r--kmscube/cube-egl.cpp5
-rw-r--r--kmscube/cube-egl.h4
-rw-r--r--kmscube/cube-gbm.cpp20
-rw-r--r--kmscube/cube-gles2.cpp119
-rw-r--r--kmscube/cube-null.cpp4
-rw-r--r--kmscube/cube-wl.cpp32
-rw-r--r--kmscube/cube-x11.cpp54
-rw-r--r--kmscube/cube.cpp23
-rw-r--r--kmscube/cube.h1
-rw-r--r--kmscube/esTransform.cpp110
-rw-r--r--kmscube/esTransform.h18
11 files changed, 183 insertions, 207 deletions
diff --git a/kmscube/cube-egl.cpp b/kmscube/cube-egl.cpp
index 81b3107..5f23c4e 100644
--- a/kmscube/cube-egl.cpp
+++ b/kmscube/cube-egl.cpp
@@ -22,7 +22,7 @@ static void print_egl_config(EGLDisplay dpy, EGLConfig cfg)
getconf(EGL_NATIVE_VISUAL_TYPE));
}
-EglState::EglState(void *native_display)
+EglState::EglState(void* native_display)
{
EGLBoolean b;
EGLint major, minor, n;
@@ -60,7 +60,6 @@ EglState::EglState(void *native_display)
b = eglBindAPI(EGL_OPENGL_ES_API);
FAIL_IF(!b, "failed to bind api EGL_OPENGL_ES_API");
-
if (s_verbose) {
EGLint numConfigs;
b = eglGetConfigs(m_display, nullptr, 0, &numConfigs);
@@ -96,7 +95,7 @@ EglState::~EglState()
eglTerminate(m_display);
}
-EglSurface::EglSurface(const EglState &egl, void *native_window)
+EglSurface::EglSurface(const EglState& egl, void* native_window)
: egl(egl)
{
esurface = eglCreateWindowSurface(egl.display(), egl.config(), (EGLNativeWindowType)native_window, NULL);
diff --git a/kmscube/cube-egl.h b/kmscube/cube-egl.h
index a7de103..f492d07 100644
--- a/kmscube/cube-egl.h
+++ b/kmscube/cube-egl.h
@@ -5,7 +5,7 @@
class EglState
{
public:
- EglState(void *native_display);
+ EglState(void* native_display);
~EglState();
EGLDisplay display() const { return m_display; }
@@ -21,7 +21,7 @@ private:
class EglSurface
{
public:
- EglSurface(const EglState& egl, void *native_window);
+ EglSurface(const EglState& egl, void* native_window);
~EglSurface();
void make_current();
diff --git a/kmscube/cube-gbm.cpp b/kmscube/cube-gbm.cpp
index e239a0c..d998f0b 100644
--- a/kmscube/cube-gbm.cpp
+++ b/kmscube/cube-gbm.cpp
@@ -74,7 +74,7 @@ public:
return gbm_surface_lock_front_buffer(m_surface);
}
- void release_buffer(gbm_bo *bo)
+ void release_buffer(gbm_bo* bo)
{
gbm_surface_release_buffer(m_surface, bo);
}
@@ -116,13 +116,13 @@ public:
eglSwapBuffers(egl.display(), esurface);
}
- static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
+ static void drm_fb_destroy_callback(struct gbm_bo* bo, void* data)
{
auto fb = reinterpret_cast<Framebuffer*>(data);
delete fb;
}
- static Framebuffer* drm_fb_get_from_bo(struct gbm_bo *bo, Card& card)
+ static Framebuffer* drm_fb_get_from_bo(struct gbm_bo* bo, Card& card)
{
auto fb = reinterpret_cast<Framebuffer*>(gbm_bo_get_user_data(bo));
if (fb)
@@ -134,9 +134,9 @@ public:
uint32_t handle = gbm_bo_get_handle(bo).u32;
PixelFormat format = (PixelFormat)gbm_bo_get_format(bo);
- vector<uint32_t> handles { handle };
- vector<uint32_t> strides { stride };
- vector<uint32_t> offsets { 0 };
+ vector<uint32_t> handles{ handle };
+ vector<uint32_t> strides{ stride };
+ vector<uint32_t> offsets{ 0 };
fb = new ExtFramebuffer(card, width, height, format, handles, strides, offsets);
@@ -237,7 +237,7 @@ private:
{
++m_frame_num;
- if (m_frame_num % 100 == 0) {
+ if (m_frame_num % 100 == 0) {
auto t2 = chrono::steady_clock::now();
chrono::duration<float> fsec = t2 - m_t1;
printf("fps: %f\n", 100.0 / fsec.count());
@@ -351,11 +351,11 @@ void main_gbm()
for (auto& out : outputs)
out->start_flipping();
- struct pollfd fds[2] = { };
+ struct pollfd fds[2] = {};
fds[0].fd = 0;
- fds[0].events = POLLIN;
+ fds[0].events = POLLIN;
fds[1].fd = card.fd();
- fds[1].events = POLLIN;
+ fds[1].events = POLLIN;
while (!s_need_exit || s_flip_pending) {
int r = poll(fds, ARRAY_SIZE(fds), -1);
diff --git a/kmscube/cube-gles2.cpp b/kmscube/cube-gles2.cpp
index 05567ea..854c90e 100644
--- a/kmscube/cube-gles2.cpp
+++ b/kmscube/cube-gles2.cpp
@@ -41,40 +41,40 @@ GlScene::GlScene()
-1.0f, -1.0f, -1.0f, // point black
+1.0f, -1.0f, -1.0f, // point red
-1.0f, -1.0f, +1.0f, // point blue
- +1.0f, -1.0f, +1.0f // point magenta
+ +1.0f, -1.0f, +1.0f // point magenta
};
static const GLfloat vColors[] = {
// front
- 0.0f, 0.0f, 1.0f, // blue
- 1.0f, 0.0f, 1.0f, // magenta
- 0.0f, 1.0f, 1.0f, // cyan
- 1.0f, 1.0f, 1.0f, // white
+ 0.0f, 0.0f, 1.0f, // blue
+ 1.0f, 0.0f, 1.0f, // magenta
+ 0.0f, 1.0f, 1.0f, // cyan
+ 1.0f, 1.0f, 1.0f, // white
// back
- 1.0f, 0.0f, 0.0f, // red
- 0.0f, 0.0f, 0.0f, // black
- 1.0f, 1.0f, 0.0f, // yellow
- 0.0f, 1.0f, 0.0f, // green
+ 1.0f, 0.0f, 0.0f, // red
+ 0.0f, 0.0f, 0.0f, // black
+ 1.0f, 1.0f, 0.0f, // yellow
+ 0.0f, 1.0f, 0.0f, // green
// right
- 1.0f, 0.0f, 1.0f, // magenta
- 1.0f, 0.0f, 0.0f, // red
- 1.0f, 1.0f, 1.0f, // white
- 1.0f, 1.0f, 0.0f, // yellow
+ 1.0f, 0.0f, 1.0f, // magenta
+ 1.0f, 0.0f, 0.0f, // red
+ 1.0f, 1.0f, 1.0f, // white
+ 1.0f, 1.0f, 0.0f, // yellow
// left
- 0.0f, 0.0f, 0.0f, // black
- 0.0f, 0.0f, 1.0f, // blue
- 0.0f, 1.0f, 0.0f, // green
- 0.0f, 1.0f, 1.0f, // cyan
+ 0.0f, 0.0f, 0.0f, // black
+ 0.0f, 0.0f, 1.0f, // blue
+ 0.0f, 1.0f, 0.0f, // green
+ 0.0f, 1.0f, 1.0f, // cyan
// top
- 0.0f, 1.0f, 1.0f, // cyan
- 1.0f, 1.0f, 1.0f, // white
- 0.0f, 1.0f, 0.0f, // green
- 1.0f, 1.0f, 0.0f, // yellow
+ 0.0f, 1.0f, 1.0f, // cyan
+ 1.0f, 1.0f, 1.0f, // white
+ 0.0f, 1.0f, 0.0f, // green
+ 1.0f, 1.0f, 0.0f, // yellow
// bottom
- 0.0f, 0.0f, 0.0f, // black
- 1.0f, 0.0f, 0.0f, // red
- 0.0f, 0.0f, 1.0f, // blue
- 1.0f, 0.0f, 1.0f // magenta
+ 0.0f, 0.0f, 0.0f, // black
+ 1.0f, 0.0f, 0.0f, // red
+ 0.0f, 0.0f, 1.0f, // blue
+ 1.0f, 0.0f, 1.0f // magenta
};
static const GLfloat vNormals[] = {
@@ -107,43 +107,42 @@ GlScene::GlScene()
+0.0f, -1.0f, +0.0f, // down
+0.0f, -1.0f, +0.0f, // down
+0.0f, -1.0f, +0.0f, // down
- +0.0f, -1.0f, +0.0f // down
+ +0.0f, -1.0f, +0.0f // down
};
- static const char *vertex_shader_source =
- "uniform mat4 modelviewMatrix; \n"
- "uniform mat4 modelviewprojectionMatrix;\n"
- "uniform mat3 normalMatrix; \n"
- " \n"
- "attribute vec4 in_position; \n"
- "attribute vec3 in_normal; \n"
- "attribute vec4 in_color; \n"
- "\n"
- "vec4 lightSource = vec4(2.0, 2.0, 20.0, 0.0);\n"
- " \n"
- "varying vec4 vVaryingColor; \n"
- " \n"
- "void main() \n"
- "{ \n"
- " gl_Position = modelviewprojectionMatrix * in_position;\n"
- " vec3 vEyeNormal = normalMatrix * in_normal;\n"
- " vec4 vPosition4 = modelviewMatrix * in_position;\n"
- " vec3 vPosition3 = vPosition4.xyz / vPosition4.w;\n"
- " vec3 vLightDir = normalize(lightSource.xyz - vPosition3);\n"
- " float diff = max(0.0, dot(vEyeNormal, vLightDir));\n"
- " vVaryingColor = vec4(diff * in_color.rgb, 1.0);\n"
- "} \n";
-
- static const char *fragment_shader_source =
- "precision mediump float; \n"
- " \n"
- "varying vec4 vVaryingColor; \n"
- " \n"
- "void main() \n"
- "{ \n"
- " gl_FragColor = vVaryingColor; \n"
- "} \n";
-
+ static const char* vertex_shader_source =
+ "uniform mat4 modelviewMatrix; \n"
+ "uniform mat4 modelviewprojectionMatrix;\n"
+ "uniform mat3 normalMatrix; \n"
+ " \n"
+ "attribute vec4 in_position; \n"
+ "attribute vec3 in_normal; \n"
+ "attribute vec4 in_color; \n"
+ "\n"
+ "vec4 lightSource = vec4(2.0, 2.0, 20.0, 0.0);\n"
+ " \n"
+ "varying vec4 vVaryingColor; \n"
+ " \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = modelviewprojectionMatrix * in_position;\n"
+ " vec3 vEyeNormal = normalMatrix * in_normal;\n"
+ " vec4 vPosition4 = modelviewMatrix * in_position;\n"
+ " vec3 vPosition3 = vPosition4.xyz / vPosition4.w;\n"
+ " vec3 vLightDir = normalize(lightSource.xyz - vPosition3);\n"
+ " float diff = max(0.0, dot(vEyeNormal, vLightDir));\n"
+ " vVaryingColor = vec4(diff * in_color.rgb, 1.0);\n"
+ "} \n";
+
+ static const char* fragment_shader_source =
+ "precision mediump float; \n"
+ " \n"
+ "varying vec4 vVaryingColor; \n"
+ " \n"
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vVaryingColor; \n"
+ "} \n";
if (s_verbose) {
printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
diff --git a/kmscube/cube-null.cpp b/kmscube/cube-null.cpp
index f8f2091..1fba1db 100644
--- a/kmscube/cube-null.cpp
+++ b/kmscube/cube-null.cpp
@@ -18,9 +18,9 @@ void main_null()
int framenum = 0;
- struct pollfd fds[1] = { };
+ struct pollfd fds[1] = {};
fds[0].fd = 0;
- fds[0].events = POLLIN;
+ fds[0].events = POLLIN;
while (true) {
int r = poll(fds, ARRAY_SIZE(fds), 0);
diff --git a/kmscube/cube-wl.cpp b/kmscube/cube-wl.cpp
index de75f88..136a4ed 100644
--- a/kmscube/cube-wl.cpp
+++ b/kmscube/cube-wl.cpp
@@ -9,18 +9,18 @@
#include "cube-egl.h"
#include "cube-gles2.h"
-static struct wl_compositor *s_compositor = NULL;
-static struct wl_shell *s_shell = NULL;
+static struct wl_compositor* s_compositor = NULL;
+static struct wl_shell* s_shell = NULL;
static char s_running = 1;
struct window {
- struct wl_surface *surface;
- struct wl_shell_surface *shell_surface;
- struct wl_egl_window *egl_window;
+ struct wl_surface* surface;
+ struct wl_shell_surface* shell_surface;
+ struct wl_egl_window* egl_window;
};
// listeners
-static void registry_add_object(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
+static void registry_add_object(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
{
if (!strcmp(interface, "wl_compositor"))
s_compositor = (struct wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 0);
@@ -28,35 +28,33 @@ static void registry_add_object(void *data, struct wl_registry *registry, uint32
s_shell = (struct wl_shell*)wl_registry_bind(registry, name, &wl_shell_interface, 0);
}
-static void registry_remove_object(void *data, struct wl_registry *registry, uint32_t name)
+static void registry_remove_object(void* data, struct wl_registry* registry, uint32_t name)
{
-
}
static struct wl_registry_listener registry_listener = { &registry_add_object, &registry_remove_object };
-static void shell_surface_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial)
+static void shell_surface_ping(void* data, struct wl_shell_surface* shell_surface, uint32_t serial)
{
wl_shell_surface_pong(shell_surface, serial);
}
-static void shell_surface_configure(void *data, struct wl_shell_surface *shell_surface, uint32_t edges, int32_t width, int32_t height)
+static void shell_surface_configure(void* data, struct wl_shell_surface* shell_surface, uint32_t edges, int32_t width, int32_t height)
{
- struct window *window = (struct window*)data;
+ struct window* window = (struct window*)data;
wl_egl_window_resize(window->egl_window, width, height, 0, 0);
}
-static void shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface)
+static void shell_surface_popup_done(void* data, struct wl_shell_surface* shell_surface)
{
-
}
static struct wl_shell_surface_listener shell_surface_listener = {
&shell_surface_ping, &shell_surface_configure, &shell_surface_popup_done
};
-static void create_window(struct window *window, int32_t width, int32_t height)
+static void create_window(struct window* window, int32_t width, int32_t height)
{
window->surface = wl_compositor_create_surface(s_compositor);
window->shell_surface = wl_shell_get_shell_surface(s_shell, window->surface);
@@ -65,7 +63,7 @@ static void create_window(struct window *window, int32_t width, int32_t height)
window->egl_window = wl_egl_window_create(window->surface, width, height);
}
-static void delete_window(struct window *window)
+static void delete_window(struct window* window)
{
wl_egl_window_destroy(window->egl_window);
wl_shell_surface_destroy(window->shell_surface);
@@ -74,8 +72,8 @@ static void delete_window(struct window *window)
void main_wl()
{
- struct wl_display *display = wl_display_connect(NULL);
- struct wl_registry *registry = wl_display_get_registry(display);
+ struct wl_display* display = wl_display_connect(NULL);
+ struct wl_registry* registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, NULL);
wl_display_roundtrip(display);
diff --git a/kmscube/cube-x11.cpp b/kmscube/cube-x11.cpp
index 47a1d2b..ae018ea 100644
--- a/kmscube/cube-x11.cpp
+++ b/kmscube/cube-x11.cpp
@@ -10,7 +10,7 @@
using namespace std;
-static void main_loop(Display* dpy, xcb_connection_t *c, xcb_window_t window, uint32_t width, uint32_t height)
+static void main_loop(Display* dpy, xcb_connection_t* c, xcb_window_t window, uint32_t width, uint32_t height)
{
EglState egl(dpy);
EglSurface surface(egl, (void*)(uintptr_t)window);
@@ -25,10 +25,9 @@ static void main_loop(Display* dpy, xcb_connection_t *c, xcb_window_t window, ui
bool need_exit = false;
- xcb_generic_event_t *event;
+ xcb_generic_event_t* event;
while (true) {
-
- while ((event = xcb_poll_for_event (c))) {
+ while ((event = xcb_poll_for_event(c))) {
bool handled = false;
uint8_t response_type = event->response_type & ~0x80;
@@ -40,7 +39,7 @@ static void main_loop(Display* dpy, xcb_connection_t *c, xcb_window_t window, ui
case XCB_KEY_PRESS: {
handled = true;
- xcb_key_press_event_t *kp = (xcb_key_press_event_t *)event;
+ xcb_key_press_event_t* kp = (xcb_key_press_event_t*)event;
if (kp->detail == 24 || kp->detail == 9) {
printf("Exit due to keypress\n");
need_exit = true;
@@ -85,14 +84,14 @@ void main_x11()
Display* dpy = XOpenDisplay(NULL);
FAIL_IF(!dpy, "Failed to connect to the X server");
- xcb_connection_t *c = XGetXCBConnection(dpy);
+ xcb_connection_t* c = XGetXCBConnection(dpy);
/* Acquire event queue ownership */
XSetEventQueueOwner(dpy, XCBOwnsEventQueue);
/* Get the first screen */
- const xcb_setup_t *setup = xcb_get_setup (c);
- xcb_screen_t *screen = xcb_setup_roots_iterator (setup).data;
+ const xcb_setup_t* setup = xcb_get_setup(c);
+ xcb_screen_t* screen = xcb_setup_roots_iterator(setup).data;
/* Create the window */
@@ -115,23 +114,22 @@ void main_x11()
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS,
};
- xcb_window_t window = xcb_generate_id (c);
- xcb_create_window (c, /* Connection */
- XCB_COPY_FROM_PARENT, /* depth (same as root)*/
- window, /* window Id */
- screen->root, /* parent window */
- 0, 0, /* x, y */
- width, height, /* width, height */
- 0, /* border_width */
- XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
- screen->root_visual, /* visual */
- xcb_window_attrib_mask,
- xcb_window_attrib_list);
-
- if (s_fullscreen)
- {
- const char *net_wm_state = "_NET_WM_STATE";
- const char *net_wm_state_fullscreen = "_NET_WM_STATE_FULLSCREEN";
+ xcb_window_t window = xcb_generate_id(c);
+ xcb_create_window(c, /* Connection */
+ XCB_COPY_FROM_PARENT, /* depth (same as root)*/
+ window, /* window Id */
+ screen->root, /* parent window */
+ 0, 0, /* x, y */
+ width, height, /* width, height */
+ 0, /* border_width */
+ XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
+ screen->root_visual, /* visual */
+ xcb_window_attrib_mask,
+ xcb_window_attrib_list);
+
+ if (s_fullscreen) {
+ const char* net_wm_state = "_NET_WM_STATE";
+ const char* net_wm_state_fullscreen = "_NET_WM_STATE_FULLSCREEN";
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(c, 0, strlen(net_wm_state), net_wm_state);
xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(c, cookie, 0);
@@ -139,11 +137,11 @@ void main_x11()
xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(c, 0, strlen(net_wm_state_fullscreen), net_wm_state_fullscreen);
xcb_intern_atom_reply_t* reply2 = xcb_intern_atom_reply(c, cookie2, 0);
- xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, reply->atom, XCB_ATOM_ATOM , 32, 1, (void*)&reply2->atom);
+ xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, reply->atom, XCB_ATOM_ATOM, 32, 1, (void*)&reply2->atom);
}
- xcb_map_window (c, window);
- xcb_flush (c);
+ xcb_map_window(c, window);
+ xcb_flush(c);
main_loop(dpy, c, window, width, height);
diff --git a/kmscube/cube.cpp b/kmscube/cube.cpp
index 4129554..406bb8d 100644
--- a/kmscube/cube.cpp
+++ b/kmscube/cube.cpp
@@ -34,24 +34,21 @@ bool s_verbose;
bool s_fullscreen;
unsigned s_num_frames;
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
OptionSet optionset = {
Option("v|verbose",
- [&]()
- {
- s_verbose = true;
- }),
+ [&]() {
+ s_verbose = true;
+ }),
Option("f|fullscreen",
- [&]()
- {
- s_fullscreen = true;
- }),
+ [&]() {
+ s_fullscreen = true;
+ }),
Option("n|numframes=",
- [&](string s)
- {
- s_num_frames = stoi(s);
- }),
+ [&](string s) {
+ s_num_frames = stoi(s);
+ }),
};
optionset.parse(argc, argv);
diff --git a/kmscube/cube.h b/kmscube/cube.h
index 6368162..18ab0e0 100644
--- a/kmscube/cube.h
+++ b/kmscube/cube.h
@@ -8,4 +8,3 @@ void main_null();
void main_gbm();
void main_x11();
void main_wl();
-
diff --git a/kmscube/esTransform.cpp b/kmscube/esTransform.cpp
index 899c038..daa28ac 100644
--- a/kmscube/esTransform.cpp
+++ b/kmscube/esTransform.cpp
@@ -46,8 +46,7 @@
#define PI 3.1415926535897932384626433832795f
-void
-esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz)
+void esScale(ESMatrix* result, GLfloat sx, GLfloat sy, GLfloat sz)
{
result->m[0][0] *= sx;
result->m[0][1] *= sx;
@@ -65,8 +64,7 @@ esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz)
result->m[2][3] *= sz;
}
-void
-esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz)
+void esTranslate(ESMatrix* result, GLfloat tx, GLfloat ty, GLfloat tz)
{
result->m[3][0] += (result->m[0][0] * tx + result->m[1][0] * ty + result->m[2][0] * tz);
result->m[3][1] += (result->m[0][1] * tx + result->m[1][1] * ty + result->m[2][1] * tz);
@@ -74,16 +72,14 @@ esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz)
result->m[3][3] += (result->m[0][3] * tx + result->m[1][3] * ty + result->m[2][3] * tz);
}
-void
-esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
+void esRotate(ESMatrix* result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{
GLfloat sinAngle, cosAngle;
GLfloat mag = sqrtf(x * x + y * y + z * z);
- sinAngle = sinf ( angle * PI / 180.0f );
- cosAngle = cosf ( angle * PI / 180.0f );
- if ( mag > 0.0f )
- {
+ sinAngle = sinf(angle * PI / 180.0f);
+ cosAngle = cosf(angle * PI / 180.0f);
+ if (mag > 0.0f) {
GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs;
GLfloat oneMinusCos;
ESMatrix rotMat;
@@ -123,20 +119,19 @@ esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
rotMat.m[3][2] = 0.0F;
rotMat.m[3][3] = 1.0F;
- esMatrixMultiply( result, &rotMat, result );
+ esMatrixMultiply(result, &rotMat, result);
}
}
-void
-esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
+void esFrustum(ESMatrix* result, float left, float right, float bottom, float top, float nearZ, float farZ)
{
- float deltaX = right - left;
- float deltaY = top - bottom;
- float deltaZ = farZ - nearZ;
- ESMatrix frust;
+ float deltaX = right - left;
+ float deltaY = top - bottom;
+ float deltaZ = farZ - nearZ;
+ ESMatrix frust;
- if ( (nearZ <= 0.0f) || (farZ <= 0.0f) ||
- (deltaX <= 0.0f) || (deltaY <= 0.0f) || (deltaZ <= 0.0f) )
+ if ((nearZ <= 0.0f) || (farZ <= 0.0f) ||
+ (deltaX <= 0.0f) || (deltaY <= 0.0f) || (deltaZ <= 0.0f))
return;
frust.m[0][0] = 2.0f * nearZ / deltaX;
@@ -156,27 +151,24 @@ esFrustum(ESMatrix *result, float left, float right, float bottom, float top, fl
esMatrixMultiply(result, &frust, result);
}
-
-void
-esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ)
+void esPerspective(ESMatrix* result, float fovy, float aspect, float nearZ, float farZ)
{
GLfloat frustumW, frustumH;
- frustumH = tanf( fovy / 360.0f * PI ) * nearZ;
+ frustumH = tanf(fovy / 360.0f * PI) * nearZ;
frustumW = frustumH * aspect;
- esFrustum( result, -frustumW, frustumW, -frustumH, frustumH, nearZ, farZ );
+ esFrustum(result, -frustumW, frustumW, -frustumH, frustumH, nearZ, farZ);
}
-void
-esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ)
+void esOrtho(ESMatrix* result, float left, float right, float bottom, float top, float nearZ, float farZ)
{
- float deltaX = right - left;
- float deltaY = top - bottom;
- float deltaZ = farZ - nearZ;
- ESMatrix ortho;
+ float deltaX = right - left;
+ float deltaY = top - bottom;
+ float deltaZ = farZ - nearZ;
+ ESMatrix ortho;
- if ( (deltaX == 0.0f) || (deltaY == 0.0f) || (deltaZ == 0.0f) )
+ if ((deltaX == 0.0f) || (deltaY == 0.0f) || (deltaZ == 0.0f))
return;
esMatrixLoadIdentity(&ortho);
@@ -190,41 +182,36 @@ esOrtho(ESMatrix *result, float left, float right, float bottom, float top, floa
esMatrixMultiply(result, &ortho, result);
}
-
-void
-esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB)
+void esMatrixMultiply(ESMatrix* result, ESMatrix* srcA, ESMatrix* srcB)
{
- ESMatrix tmp;
- int i;
-
- for (i=0; i<4; i++)
- {
- tmp.m[i][0] = (srcA->m[i][0] * srcB->m[0][0]) +
- (srcA->m[i][1] * srcB->m[1][0]) +
- (srcA->m[i][2] * srcB->m[2][0]) +
- (srcA->m[i][3] * srcB->m[3][0]) ;
-
- tmp.m[i][1] = (srcA->m[i][0] * srcB->m[0][1]) +
- (srcA->m[i][1] * srcB->m[1][1]) +
- (srcA->m[i][2] * srcB->m[2][1]) +
- (srcA->m[i][3] * srcB->m[3][1]) ;
-
- tmp.m[i][2] = (srcA->m[i][0] * srcB->m[0][2]) +
- (srcA->m[i][1] * srcB->m[1][2]) +
- (srcA->m[i][2] * srcB->m[2][2]) +
- (srcA->m[i][3] * srcB->m[3][2]) ;
-
- tmp.m[i][3] = (srcA->m[i][0] * srcB->m[0][3]) +
- (srcA->m[i][1] * srcB->m[1][3]) +
- (srcA->m[i][2] * srcB->m[2][3]) +
- (srcA->m[i][3] * srcB->m[3][3]) ;
+ ESMatrix tmp;
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ tmp.m[i][0] = (srcA->m[i][0] * srcB->m[0][0]) +
+ (srcA->m[i][1] * srcB->m[1][0]) +
+ (srcA->m[i][2] * srcB->m[2][0]) +
+ (srcA->m[i][3] * srcB->m[3][0]);
+
+ tmp.m[i][1] = (srcA->m[i][0] * srcB->m[0][1]) +
+ (srcA->m[i][1] * srcB->m[1][1]) +
+ (srcA->m[i][2] * srcB->m[2][1]) +
+ (srcA->m[i][3] * srcB->m[3][1]);
+
+ tmp.m[i][2] = (srcA->m[i][0] * srcB->m[0][2]) +
+ (srcA->m[i][1] * srcB->m[1][2]) +
+ (srcA->m[i][2] * srcB->m[2][2]) +
+ (srcA->m[i][3] * srcB->m[3][2]);
+
+ tmp.m[i][3] = (srcA->m[i][0] * srcB->m[0][3]) +
+ (srcA->m[i][1] * srcB->m[1][3]) +
+ (srcA->m[i][2] * srcB->m[2][3]) +
+ (srcA->m[i][3] * srcB->m[3][3]);
}
memcpy(result, &tmp, sizeof(ESMatrix));
}
-
-void
-esMatrixLoadIdentity(ESMatrix *result)
+void esMatrixLoadIdentity(ESMatrix* result)
{
memset(result, 0x0, sizeof(ESMatrix));
result->m[0][0] = 1.0f;
@@ -232,4 +219,3 @@ esMatrixLoadIdentity(ESMatrix *result)
result->m[2][2] = 1.0f;
result->m[3][3] = 1.0f;
}
-
diff --git a/kmscube/esTransform.h b/kmscube/esTransform.h
index c0383ab..f89e7b4 100644
--- a/kmscube/esTransform.h
+++ b/kmscube/esTransform.h
@@ -52,7 +52,7 @@ extern "C" {
typedef struct
{
- GLfloat m[4][4];
+ GLfloat m[4][4];
} ESMatrix;
//
@@ -60,14 +60,14 @@ typedef struct
/// \param result Specifies the input matrix. Scaled matrix is returned in result.
/// \param sx, sy, sz Scale factors along the x, y and z axes respectively
//
-void esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz);
+void esScale(ESMatrix* result, GLfloat sx, GLfloat sy, GLfloat sz);
//
/// \brief multiply matrix specified by result with a translation matrix and return new matrix in result
/// \param result Specifies the input matrix. Translated matrix is returned in result.
/// \param tx, ty, tz Scale factors along the x, y and z axes respectively
//
-void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz);
+void esTranslate(ESMatrix* result, GLfloat tx, GLfloat ty, GLfloat tz);
//
/// \brief multiply matrix specified by result with a rotation matrix and return new matrix in result
@@ -75,7 +75,7 @@ void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz);
/// \param angle Specifies the angle of rotation, in degrees.
/// \param x, y, z Specify the x, y and z coordinates of a vector, respectively
//
-void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+void esRotate(ESMatrix* result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
//
// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
@@ -84,7 +84,7 @@ void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
/// \param bottom, top Coordinates for the bottom and top horizontal clipping planes
/// \param nearZ, farZ Distances to the near and far depth clipping planes. Both distances must be positive.
//
-void esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
+void esFrustum(ESMatrix* result, float left, float right, float bottom, float top, float nearZ, float farZ);
//
/// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
@@ -94,7 +94,7 @@ void esFrustum(ESMatrix *result, float left, float right, float bottom, float to
/// \param nearZ Near plane distance
/// \param farZ Far plane distance
//
-void esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ);
+void esPerspective(ESMatrix* result, float fovy, float aspect, float nearZ, float farZ);
//
/// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
@@ -103,20 +103,20 @@ void esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, floa
/// \param bottom, top Coordinates for the bottom and top horizontal clipping planes
/// \param nearZ, farZ Distances to the near and far depth clipping planes. These values are negative if plane is behind the viewer
//
-void esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
+void esOrtho(ESMatrix* result, float left, float right, float bottom, float top, float nearZ, float farZ);
//
/// \brief perform the following operation - result matrix = srcA matrix * srcB matrix
/// \param result Returns multiplied matrix
/// \param srcA, srcB Input matrices to be multiplied
//
-void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB);
+void esMatrixMultiply(ESMatrix* result, ESMatrix* srcA, ESMatrix* srcB);
//
//// \brief return an indentity matrix
//// \param result returns identity matrix
//
-void esMatrixLoadIdentity(ESMatrix *result);
+void esMatrixLoadIdentity(ESMatrix* result);
#ifdef __cplusplus
}