This commit is contained in:
bkaradzic 2014-05-14 20:57:37 -07:00
parent b685a02947
commit e29be87bd2
6 changed files with 77 additions and 190 deletions

View file

@ -206,35 +206,6 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */); return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
} }
void mtxScaleRotateTranslate(float* _result
, const float _scaleX
, const float _scaleY
, const float _scaleZ
, const float _rotX
, const float _rotY
, const float _rotZ
, const float _translateX
, const float _translateY
, const float _translateZ
)
{
float mtxRotateTranslate[16];
float mtxScale[16];
mtxRotateXYZ(mtxRotateTranslate, _rotX, _rotY, _rotZ);
mtxRotateTranslate[12] = _translateX;
mtxRotateTranslate[13] = _translateY;
mtxRotateTranslate[14] = _translateZ;
memset(mtxScale, 0, sizeof(float)*16);
mtxScale[0] = _scaleX;
mtxScale[5] = _scaleY;
mtxScale[10] = _scaleZ;
mtxScale[15] = 1.0f;
mtxMul(_result, mtxScale, mtxRotateTranslate);
}
void mtxReflected(float*__restrict _result void mtxReflected(float*__restrict _result
, const float* __restrict _p /* plane */ , const float* __restrict _p /* plane */
, const float* __restrict _n /* normal */ , const float* __restrict _n /* normal */
@ -1136,7 +1107,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Floor position. // Floor position.
float floorMtx[16]; float floorMtx[16];
mtxScaleRotateTranslate(floorMtx mtxSRT(floorMtx
, 20.0f //scaleX , 20.0f //scaleX
, 20.0f //scaleY , 20.0f //scaleY
, 20.0f //scaleZ , 20.0f //scaleZ
@ -1150,7 +1121,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Bunny position. // Bunny position.
float bunnyMtx[16]; float bunnyMtx[16];
mtxScaleRotateTranslate(bunnyMtx mtxSRT(bunnyMtx
, 5.0f , 5.0f
, 5.0f , 5.0f
, 5.0f , 5.0f
@ -1175,7 +1146,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
float columnMtx[4][16]; float columnMtx[4][16];
for (uint8_t ii = 0; ii < 4; ++ii) for (uint8_t ii = 0; ii < 4; ++ii)
{ {
mtxScaleRotateTranslate(columnMtx[ii] mtxSRT(columnMtx[ii]
, 1.0f , 1.0f
, 1.0f , 1.0f
, 1.0f , 1.0f
@ -1192,7 +1163,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
float cubeMtx[numCubes][16]; float cubeMtx[numCubes][16];
for (uint16_t ii = 0; ii < numCubes; ++ii) for (uint16_t ii = 0; ii < numCubes; ++ii)
{ {
mtxScaleRotateTranslate(cubeMtx[ii] mtxSRT(cubeMtx[ii]
, 1.0f , 1.0f
, 1.0f , 1.0f
, 1.0f , 1.0f
@ -1443,7 +1414,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Draw floor bottom. // Draw floor bottom.
float floorBottomMtx[16]; float floorBottomMtx[16];
mtxScaleRotateTranslate(floorBottomMtx mtxSRT(floorBottomMtx
, 20.0f //scaleX , 20.0f //scaleX
, 20.0f //scaleY , 20.0f //scaleY
, 20.0f //scaleZ , 20.0f //scaleZ

View file

@ -176,35 +176,6 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */); return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
} }
void mtxScaleRotateTranslate(float* _result
, const float _scaleX
, const float _scaleY
, const float _scaleZ
, const float _rotX
, const float _rotY
, const float _rotZ
, const float _translateX
, const float _translateY
, const float _translateZ
)
{
float mtxRotateTranslate[16];
float mtxScale[16];
mtxRotateXYZ(mtxRotateTranslate, _rotX, _rotY, _rotZ);
mtxRotateTranslate[12] = _translateX;
mtxRotateTranslate[13] = _translateY;
mtxRotateTranslate[14] = _translateZ;
memset(mtxScale, 0, 16*sizeof(float) );
mtxScale[0] = _scaleX;
mtxScale[5] = _scaleY;
mtxScale[10] = _scaleZ;
mtxScale[15] = 1.0f;
mtxMul(_result, mtxScale, mtxRotateTranslate);
}
void mtxBillboard(float* __restrict _result void mtxBillboard(float* __restrict _result
, const float* __restrict _view , const float* __restrict _view
, const float* __restrict _pos , const float* __restrict _pos
@ -1277,7 +1248,7 @@ struct Instance
memcpy(s_uniforms.m_color, m_color, 3*sizeof(float) ); memcpy(s_uniforms.m_color, m_color, 3*sizeof(float) );
float mtx[16]; float mtx[16];
mtxScaleRotateTranslate(mtx mtxSRT(mtx
, m_scale[0] , m_scale[0]
, m_scale[1] , m_scale[1]
, m_scale[2] , m_scale[2]
@ -2734,7 +2705,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Compute transform for shadow volume. // Compute transform for shadow volume.
float shadowVolumeMtx[16]; float shadowVolumeMtx[16];
mtxScaleRotateTranslate(shadowVolumeMtx mtxSRT(shadowVolumeMtx
, instance.m_scale[0] , instance.m_scale[0]
, instance.m_scale[1] , instance.m_scale[1]
, instance.m_scale[2] , instance.m_scale[2]

View file

@ -54,7 +54,6 @@ struct PosNormalVertex
uint32_t m_normal; uint32_t m_normal;
}; };
static const float s_texcoord = 5.0f;
static const uint32_t s_numHPlaneVertices = 4; static const uint32_t s_numHPlaneVertices = 4;
static PosNormalVertex s_hplaneVertices[s_numHPlaneVertices] = static PosNormalVertex s_hplaneVertices[s_numHPlaneVertices] =
{ {
@ -133,35 +132,6 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */); return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
} }
void mtxScaleRotateTranslate(float* _result
, const float _scaleX
, const float _scaleY
, const float _scaleZ
, const float _rotX
, const float _rotY
, const float _rotZ
, const float _translateX
, const float _translateY
, const float _translateZ
)
{
float mtxRotateTranslate[16];
float mtxScale[16];
mtxRotateXYZ(mtxRotateTranslate, _rotX, _rotY, _rotZ);
mtxRotateTranslate[12] = _translateX;
mtxRotateTranslate[13] = _translateY;
mtxRotateTranslate[14] = _translateZ;
memset(mtxScale, 0, sizeof(float)*16);
mtxScale[0] = _scaleX;
mtxScale[5] = _scaleY;
mtxScale[10] = _scaleZ;
mtxScale[15] = 1.0f;
mtxMul(_result, mtxScale, mtxRotateTranslate);
}
struct Aabb struct Aabb
{ {
float m_min[3]; float m_min[3];
@ -556,28 +526,28 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Setup instance matrices. // Setup instance matrices.
float mtxFloor[16]; float mtxFloor[16];
mtxScaleRotateTranslate(mtxFloor mtxSRT(mtxFloor
, 30.0f, 30.0f, 30.0f , 30.0f, 30.0f, 30.0f
, 0.0f, 0.0f, 0.0f , 0.0f, 0.0f, 0.0f
, 0.0f, 0.0f, 0.0f , 0.0f, 0.0f, 0.0f
); );
float mtxBunny[16]; float mtxBunny[16];
mtxScaleRotateTranslate(mtxBunny mtxSRT(mtxBunny
, 5.0f, 5.0f, 5.0f , 5.0f, 5.0f, 5.0f
, 0.0f, float(M_PI) - timeAccumulatorScene, 0.0f , 0.0f, float(M_PI) - timeAccumulatorScene, 0.0f
, 15.0f, 5.0f, 0.0f , 15.0f, 5.0f, 0.0f
); );
float mtxHollowcube[16]; float mtxHollowcube[16];
mtxScaleRotateTranslate(mtxHollowcube mtxSRT(mtxHollowcube
, 2.5f, 2.5f, 2.5f , 2.5f, 2.5f, 2.5f
, 0.0f, 1.56f - timeAccumulatorScene, 0.0f , 0.0f, 1.56f - timeAccumulatorScene, 0.0f
, 0.0f, 10.0f, 0.0f , 0.0f, 10.0f, 0.0f
); );
float mtxCube[16]; float mtxCube[16];
mtxScaleRotateTranslate(mtxCube mtxSRT(mtxCube
, 2.5f, 2.5f, 2.5f , 2.5f, 2.5f, 2.5f
, 0.0f, 1.56f - timeAccumulatorScene, 0.0f , 0.0f, 1.56f - timeAccumulatorScene, 0.0f
, -15.0f, 5.0f, 0.0f , -15.0f, 5.0f, 0.0f

View file

@ -323,35 +323,6 @@ static bgfx::ProgramHandle loadProgram(const char* _vsName, const char* _fsName)
return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */); return bgfx::createProgram(vsh, fsh, true /* destroy shaders when program is destroyed */);
} }
void mtxScaleRotateTranslate(float* _result
, const float _scaleX
, const float _scaleY
, const float _scaleZ
, const float _rotX
, const float _rotY
, const float _rotZ
, const float _translateX
, const float _translateY
, const float _translateZ
)
{
float mtxRotateTranslate[16];
float mtxScale[16];
mtxRotateXYZ(mtxRotateTranslate, _rotX, _rotY, _rotZ);
mtxRotateTranslate[12] = _translateX;
mtxRotateTranslate[13] = _translateY;
mtxRotateTranslate[14] = _translateZ;
memset(mtxScale, 0, sizeof(float)*16);
mtxScale[0] = _scaleX;
mtxScale[5] = _scaleY;
mtxScale[10] = _scaleZ;
mtxScale[15] = 1.0f;
mtxMul(_result, mtxScale, mtxRotateTranslate);
}
void mtxBillboard(float* __restrict _result void mtxBillboard(float* __restrict _result
, const float* __restrict _view , const float* __restrict _view
, const float* __restrict _pos , const float* __restrict _pos
@ -2322,7 +2293,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Setup instance matrices. // Setup instance matrices.
float mtxFloor[16]; float mtxFloor[16];
const float floorScale = 550.0f; const float floorScale = 550.0f;
mtxScaleRotateTranslate(mtxFloor mtxSRT(mtxFloor
, floorScale //scaleX , floorScale //scaleX
, floorScale //scaleY , floorScale //scaleY
, floorScale //scaleZ , floorScale //scaleZ
@ -2335,7 +2306,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
); );
float mtxBunny[16]; float mtxBunny[16];
mtxScaleRotateTranslate(mtxBunny mtxSRT(mtxBunny
, 5.0f , 5.0f
, 5.0f , 5.0f
, 5.0f , 5.0f
@ -2348,7 +2319,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
); );
float mtxHollowcube[16]; float mtxHollowcube[16];
mtxScaleRotateTranslate(mtxHollowcube mtxSRT(mtxHollowcube
, 2.5f , 2.5f
, 2.5f , 2.5f
, 2.5f , 2.5f
@ -2361,7 +2332,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
); );
float mtxCube[16]; float mtxCube[16];
mtxScaleRotateTranslate(mtxCube mtxSRT(mtxCube
, 2.5f , 2.5f
, 2.5f , 2.5f
, 2.5f , 2.5f
@ -2377,7 +2348,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
float mtxTrees[numTrees][16]; float mtxTrees[numTrees][16];
for (uint8_t ii = 0; ii < numTrees; ++ii) for (uint8_t ii = 0; ii < numTrees; ++ii)
{ {
mtxScaleRotateTranslate(mtxTrees[ii] mtxSRT(mtxTrees[ii]
, 2.0f , 2.0f
, 2.0f , 2.0f
, 2.0f , 2.0f
@ -3185,7 +3156,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Draw floor bottom. // Draw floor bottom.
float floorBottomMtx[16]; float floorBottomMtx[16];
mtxScaleRotateTranslate(floorBottomMtx mtxSRT(floorBottomMtx
, floorScale //scaleX , floorScale //scaleX
, floorScale //scaleY , floorScale //scaleY
, floorScale //scaleZ , floorScale //scaleZ

View file

@ -380,35 +380,6 @@ void screenSpaceQuad(float _textureWidth, float _textureHeight, bool _originBott
} }
} }
void mtxScaleRotateTranslate(float* _result
, const float _scaleX
, const float _scaleY
, const float _scaleZ
, const float _rotX
, const float _rotY
, const float _rotZ
, const float _translateX
, const float _translateY
, const float _translateZ
)
{
float mtxRotateTranslate[16];
float mtxScale[16];
mtxRotateXYZ(mtxRotateTranslate, _rotX, _rotY, _rotZ);
mtxRotateTranslate[12] = _translateX;
mtxRotateTranslate[13] = _translateY;
mtxRotateTranslate[14] = _translateZ;
memset(mtxScale, 0, sizeof(float)*16);
mtxScale[0] = _scaleX;
mtxScale[5] = _scaleY;
mtxScale[10] = _scaleZ;
mtxScale[15] = 1.0f;
mtxMul(_result, mtxScale, mtxRotateTranslate);
}
void imguiBool(const char* _str, bool& _flag, bool _enabled = true) void imguiBool(const char* _str, bool& _flag, bool _enabled = true)
{ {
if (imguiCheck(_str, _flag, _enabled) ) if (imguiCheck(_str, _flag, _enabled) )
@ -778,7 +749,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// View 1. // View 1.
float mtx[16]; float mtx[16];
mtxScaleRotateTranslate(mtx mtxSRT(mtx
, 1.0f , 1.0f
, 1.0f , 1.0f
, 1.0f , 1.0f

View file

@ -196,10 +196,10 @@ inline void mtxLookAt(float* __restrict _result, const float* __restrict _eye, c
inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far) inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far)
{ {
float height = 1.0f/tanf(_fovy*( (float)M_PI/180.0f)*0.5f); const float height = 1.0f/tanf(_fovy*( (float)M_PI/180.0f)*0.5f);
float width = height * 1.0f/_aspect; const float width = height * 1.0f/_aspect;
float aa = _far/(_far-_near); const float aa = _far/(_far-_near);
float bb = -_near * aa; const float bb = -_near * aa;
memset(_result, 0, sizeof(float)*16); memset(_result, 0, sizeof(float)*16);
_result[0] = width; _result[0] = width;
@ -230,8 +230,8 @@ inline void mtxOrtho(float* _result, float _left, float _right, float _bottom, f
inline void mtxRotateX(float* _result, float _ax) inline void mtxRotateX(float* _result, float _ax)
{ {
float sx = sinf(_ax); const float sx = sinf(_ax);
float cx = cosf(_ax); const float cx = cosf(_ax);
memset(_result, 0, sizeof(float)*16); memset(_result, 0, sizeof(float)*16);
_result[ 0] = 1.0f; _result[ 0] = 1.0f;
@ -244,8 +244,8 @@ inline void mtxRotateX(float* _result, float _ax)
inline void mtxRotateY(float* _result, float _ay) inline void mtxRotateY(float* _result, float _ay)
{ {
float sy = sinf(_ay); const float sy = sinf(_ay);
float cy = cosf(_ay); const float cy = cosf(_ay);
memset(_result, 0, sizeof(float)*16); memset(_result, 0, sizeof(float)*16);
_result[ 0] = cy; _result[ 0] = cy;
@ -258,8 +258,8 @@ inline void mtxRotateY(float* _result, float _ay)
inline void mtxRotateZ(float* _result, float _az) inline void mtxRotateZ(float* _result, float _az)
{ {
float sz = sinf(_az); const float sz = sinf(_az);
float cz = cosf(_az); const float cz = cosf(_az);
memset(_result, 0, sizeof(float)*16); memset(_result, 0, sizeof(float)*16);
_result[ 0] = cz; _result[ 0] = cz;
@ -272,10 +272,10 @@ inline void mtxRotateZ(float* _result, float _az)
inline void mtxRotateXY(float* _result, float _ax, float _ay) inline void mtxRotateXY(float* _result, float _ax, float _ay)
{ {
float sx = sinf(_ax); const float sx = sinf(_ax);
float cx = cosf(_ax); const float cx = cosf(_ax);
float sy = sinf(_ay); const float sy = sinf(_ay);
float cy = cosf(_ay); const float cy = cosf(_ay);
memset(_result, 0, sizeof(float)*16); memset(_result, 0, sizeof(float)*16);
_result[ 0] = cy; _result[ 0] = cy;
@ -291,12 +291,12 @@ inline void mtxRotateXY(float* _result, float _ax, float _ay)
inline void mtxRotateXYZ(float* _result, float _ax, float _ay, float _az) inline void mtxRotateXYZ(float* _result, float _ax, float _ay, float _az)
{ {
float sx = sinf(_ax); const float sx = sinf(_ax);
float cx = cosf(_ax); const float cx = cosf(_ax);
float sy = sinf(_ay); const float sy = sinf(_ay);
float cy = cosf(_ay); const float cy = cosf(_ay);
float sz = sinf(_az); const float sz = sinf(_az);
float cz = cosf(_az); const float cz = cosf(_az);
memset(_result, 0, sizeof(float)*16); memset(_result, 0, sizeof(float)*16);
_result[ 0] = cy*cz; _result[ 0] = cy*cz;
@ -313,12 +313,12 @@ inline void mtxRotateXYZ(float* _result, float _ax, float _ay, float _az)
inline void mtxRotateZYX(float* _result, float _ax, float _ay, float _az) inline void mtxRotateZYX(float* _result, float _ax, float _ay, float _az)
{ {
float sx = sinf(_ax); const float sx = sinf(_ax);
float cx = cosf(_ax); const float cx = cosf(_ax);
float sy = sinf(_ay); const float sy = sinf(_ay);
float cy = cosf(_ay); const float cy = cosf(_ay);
float sz = sinf(_az); const float sz = sinf(_az);
float cz = cosf(_az); const float cz = cosf(_az);
memset(_result, 0, sizeof(float)*16); memset(_result, 0, sizeof(float)*16);
_result[ 0] = cy*cz; _result[ 0] = cy*cz;
@ -333,6 +333,39 @@ inline void mtxRotateZYX(float* _result, float _ax, float _ay, float _az)
_result[15] = 1.0f; _result[15] = 1.0f;
}; };
inline void mtxSRT(float* _result, float _sx, float _sy, float _sz, float _ax, float _ay, float _az, float _tx, float _ty, float _tz)
{
const float sx = sinf(_ax);
const float cx = cosf(_ax);
const float sy = sinf(_ay);
const float cy = cosf(_ay);
const float sz = sinf(_az);
const float cz = cosf(_az);
const float sxsz = sx*sz;
const float cycz = cy*cz;
_result[ 0] = _sx * (cycz - sxsz*sy);
_result[ 1] = _sx * -cx*sz;
_result[ 2] = _sx * (cz*sy + cy*sxsz);
_result[ 3] = 0.0f;
_result[ 4] = _sy * (cz*sx*sy + cy*sz);
_result[ 5] = _sy * cx*cz;
_result[ 6] = _sy * (sy*sz -cycz*sx);
_result[ 7] = 0.0f;
_result[ 8] = _sz * -cx*sy;
_result[ 9] = _sz * sx;
_result[10] = _sz * cx*cy;
_result[11] = 0.0f;
_result[12] = _tx;
_result[13] = _ty;
_result[14] = _tz;
_result[15] = 1.0f;
}
inline void vec3MulMtx(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat) inline void vec3MulMtx(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat)
{ {
_result[0] = _vec[0] * _mat[ 0] + _vec[1] * _mat[4] + _vec[2] * _mat[ 8] + _mat[12]; _result[0] = _vec[0] * _mat[ 0] + _vec[1] * _mat[4] + _vec[2] * _mat[ 8] + _mat[12];