Cube rotation;

Angle-axis
This commit is contained in:
bjorn 2016-10-01 13:39:38 -07:00
parent 36cd7887f7
commit 9ece6c6c2c
3 changed files with 15 additions and 3 deletions

View File

@ -271,7 +271,7 @@ void lovrGraphicsLine(float* points, int count) {
lovrGraphicsDrawShape(GL_LINE_STRIP);
}
void lovrGraphicsCube(DrawMode mode, float x, float y, float z, float size) {
void lovrGraphicsCube(DrawMode mode, float x, float y, float z, float size, float angle, float axisX, float axisY, float axisZ) {
float points[] = {
// Front
-.5, .5, -.5,
@ -286,9 +286,17 @@ void lovrGraphicsCube(DrawMode mode, float x, float y, float z, float size) {
-.5, -.5, .5
};
float cos2 = cos(angle / 2);
float sin2 = sin(angle / 2);
float rw = cos2;
float rx = sin2 * axisX;
float ry = sin2 * axisY;
float rz = sin2 * axisZ;
float transform[16];
mat4_setTranslation(transform, x, y, z);
mat4_scale(transform, size, size, size);
mat4_rotate(transform, rw, rx, ry, rz);
lovrGraphicsPush();
lovrGraphicsTransform(transform);

View File

@ -75,7 +75,7 @@ void lovrGraphicsGetDimensions(int* width, int* height);
void lovrGraphicsSetShapeData(float* data, int count, unsigned int* indices, int indexCount);
void lovrGraphicsDrawShape();
void lovrGraphicsLine(float* points, int count);
void lovrGraphicsCube(DrawMode mode, float x, float y, float z, float size);
void lovrGraphicsCube(DrawMode mode, float x, float y, float z, float size, float angle, float axisX, float axisY, float axisZ);
Buffer* lovrGraphicsNewBuffer(int size, BufferDrawMode drawMode, BufferUsage usage);
Model* lovrGraphicsNewModel(const char* path);
Shader* lovrGraphicsNewShader(const char* vertexSource, const char* fragmentSource);

View File

@ -296,7 +296,11 @@ int l_lovrGraphicsCube(lua_State* L) {
float y = luaL_optnumber(L, 3, 0.f);
float z = luaL_optnumber(L, 4, 0.f);
float s = luaL_optnumber(L, 5, 1.f);
lovrGraphicsCube(*drawMode, x, y, z, s);
float angle = luaL_optnumber(L, 6, 0.f);
float axisX = luaL_optnumber(L, 7, 0.f);
float axisY = luaL_optnumber(L, 8, 0.f);
float axisZ = luaL_optnumber(L, 9, 0.f);
lovrGraphicsCube(*drawMode, x, y, z, s, angle, axisX, axisY, axisZ);
return 0;
}