more example refactoring
This commit is contained in:
@@ -19,14 +19,13 @@ bool useShadowMap=true;//false;//true;
|
||||
int shadowMapWidth=8192;
|
||||
int shadowMapHeight=8192;
|
||||
float shadowMapWorldSize=100;
|
||||
float WHEEL_MULTIPLIER=0.01f;
|
||||
float MOUSE_MOVE_MULTIPLIER = 0.4f;
|
||||
|
||||
#define MAX_POINTS_IN_BATCH 1024
|
||||
#define MAX_LINES_IN_BATCH 1024
|
||||
|
||||
|
||||
#include "OpenGLInclude.h"
|
||||
#include "b3gWindowInterface.h"
|
||||
#include "../CommonInterfaces/CommonWindowInterface.h"
|
||||
//#include "Bullet3Common/b3MinMax.h"
|
||||
|
||||
#ifndef __APPLE__
|
||||
@@ -141,20 +140,7 @@ extern int gShapeIndex;
|
||||
struct InternalDataRenderer : public GLInstanceRendererInternalData
|
||||
{
|
||||
|
||||
|
||||
b3Vector3 m_cameraPosition;
|
||||
b3Vector3 m_cameraTargetPosition;
|
||||
float m_cameraDistance;
|
||||
b3Vector3 m_cameraUp;
|
||||
float m_azi;
|
||||
float m_ele;
|
||||
|
||||
float m_mouseXpos;
|
||||
float m_mouseYpos;
|
||||
bool m_mouseInitialized;
|
||||
int m_leftMouseButton;
|
||||
int m_middleMouseButton;
|
||||
int m_rightMouseButton;
|
||||
SimpleCamera m_defaultCamera;
|
||||
|
||||
GLfloat m_projectionMatrix[16];
|
||||
GLfloat m_viewMatrix[16];
|
||||
@@ -165,25 +151,10 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
||||
|
||||
GLRenderToTexture* m_shadowMap;
|
||||
GLuint m_shadowTexture;
|
||||
int m_altPressed;
|
||||
int m_controlPressed;
|
||||
|
||||
|
||||
InternalDataRenderer() :
|
||||
m_cameraPosition(b3MakeVector3(0,0,0)),
|
||||
m_cameraTargetPosition(b3MakeVector3(15,2,-24)),
|
||||
m_cameraDistance(150),
|
||||
m_cameraUp(b3MakeVector3(0,1,0)),
|
||||
m_azi(100.f),//135.f),
|
||||
//m_ele(25.f),
|
||||
m_ele(25.f),
|
||||
m_mouseInitialized(false),
|
||||
m_leftMouseButton(0),
|
||||
m_middleMouseButton(0),
|
||||
m_rightMouseButton(0),
|
||||
m_shadowMap(0),
|
||||
m_shadowTexture(0),
|
||||
m_altPressed(0),
|
||||
m_controlPressed(0)
|
||||
m_shadowTexture(0)
|
||||
{
|
||||
//clear to zero to make it obvious if the matrix is used uninitialized
|
||||
for (int i=0;i<16;i++)
|
||||
@@ -194,113 +165,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
||||
|
||||
}
|
||||
|
||||
void wheelCallback( float deltax, float deltay)
|
||||
{
|
||||
if (!m_leftMouseButton)
|
||||
{
|
||||
|
||||
if (deltay<0 || m_cameraDistance>1)
|
||||
{
|
||||
m_cameraDistance -= deltay*0.1f;
|
||||
if (m_cameraDistance<1)
|
||||
m_cameraDistance=1;
|
||||
} else
|
||||
{
|
||||
b3Vector3 fwd = m_cameraTargetPosition-m_cameraPosition;
|
||||
fwd.normalize();
|
||||
m_cameraTargetPosition += fwd*deltay*WHEEL_MULTIPLIER;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (b3Fabs(deltax)>b3Fabs(deltay))
|
||||
{
|
||||
b3Vector3 fwd = m_cameraTargetPosition-m_cameraPosition;
|
||||
b3Vector3 side = m_cameraUp.cross(fwd);
|
||||
side.normalize();
|
||||
m_cameraTargetPosition += side * deltax*WHEEL_MULTIPLIER;
|
||||
|
||||
} else
|
||||
{
|
||||
m_cameraTargetPosition -= m_cameraUp * deltay*WHEEL_MULTIPLIER;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mouseMoveCallback(float x, float y)
|
||||
{
|
||||
// printf("moved to %f,%f\n",x,y);
|
||||
if (m_altPressed || m_controlPressed)
|
||||
{
|
||||
float xDelta = x-m_mouseXpos;
|
||||
float yDelta = y-m_mouseYpos;
|
||||
|
||||
if (m_leftMouseButton)
|
||||
{
|
||||
// if (b3Fabs(xDelta)>b3Fabs(yDelta))
|
||||
// {
|
||||
m_azi -= xDelta*MOUSE_MOVE_MULTIPLIER;
|
||||
// } else
|
||||
// {
|
||||
m_ele += yDelta*MOUSE_MOVE_MULTIPLIER;
|
||||
// }
|
||||
}
|
||||
if (m_middleMouseButton)
|
||||
{
|
||||
m_cameraTargetPosition += m_cameraUp * yDelta*0.01;
|
||||
|
||||
|
||||
b3Vector3 fwd = m_cameraTargetPosition-m_cameraPosition;
|
||||
b3Vector3 side = m_cameraUp.cross(fwd);
|
||||
side.normalize();
|
||||
m_cameraTargetPosition += side * xDelta*0.01;
|
||||
|
||||
}
|
||||
if (m_rightMouseButton)
|
||||
{
|
||||
m_cameraDistance -= xDelta*0.01f;
|
||||
m_cameraDistance -= yDelta*0.01f;
|
||||
if (m_cameraDistance<1)
|
||||
m_cameraDistance=1;
|
||||
if (m_cameraDistance>1000)
|
||||
m_cameraDistance=1000;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("m_azi/pitch = %f\n", m_azi);
|
||||
// printf("m_ele/yaw = %f\n", m_ele);
|
||||
|
||||
m_mouseXpos = x;
|
||||
m_mouseYpos = y;
|
||||
m_mouseInitialized = true;
|
||||
}
|
||||
|
||||
void mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
|
||||
if (button==0)
|
||||
m_leftMouseButton=state;
|
||||
if (button==1)
|
||||
m_middleMouseButton=state;
|
||||
|
||||
if (button==2)
|
||||
m_rightMouseButton=state;
|
||||
|
||||
m_mouseXpos = x;
|
||||
m_mouseYpos = y;
|
||||
m_mouseInitialized = true;
|
||||
}
|
||||
void keyboardCallback(int key, int state)
|
||||
{
|
||||
if (key==B3G_CONTROL)
|
||||
{
|
||||
m_controlPressed=state;
|
||||
}
|
||||
if (key==B3G_ALT)
|
||||
{
|
||||
m_altPressed = state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -309,28 +174,6 @@ struct GLInstanceRendererInternalData* GLInstancingRenderer::getInternalData()
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void b3DefaultWheelCallback(float deltax, float deltay)
|
||||
{
|
||||
if (sData2)
|
||||
sData2->wheelCallback(deltax,deltay);
|
||||
}
|
||||
void b3DefaultMouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
if (sData2)
|
||||
sData2->mouseButtonCallback(button, state, x, y);
|
||||
}
|
||||
void b3DefaultMouseMoveCallback( float x, float y)
|
||||
{
|
||||
if (sData2)
|
||||
sData2->mouseMoveCallback( x, y);
|
||||
}
|
||||
|
||||
void b3DefaultKeyboardCallback(int key, int state)
|
||||
{
|
||||
if (sData2)
|
||||
sData2->keyboardCallback(key,state);
|
||||
}
|
||||
|
||||
|
||||
static GLuint linesShader; // The line renderer
|
||||
static GLuint useShadowMapInstancingShader; // The shadow instancing renderer
|
||||
@@ -966,111 +809,6 @@ void GLInstancingRenderer::init()
|
||||
}
|
||||
|
||||
|
||||
static void b3CreateFrustum(
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
float frustum[16])
|
||||
{
|
||||
|
||||
frustum[0*4+0] = (float(2) * nearVal) / (right - left);
|
||||
frustum[0*4+1] = float(0);
|
||||
frustum[0*4+2] = float(0);
|
||||
frustum[0*4+3] = float(0);
|
||||
|
||||
frustum[1*4+0] = float(0);
|
||||
frustum[1*4+1] = (float(2) * nearVal) / (top - bottom);
|
||||
frustum[1*4+2] = float(0);
|
||||
frustum[1*4+3] = float(0);
|
||||
|
||||
frustum[2*4+0] = (right + left) / (right - left);
|
||||
frustum[2*4+1] = (top + bottom) / (top - bottom);
|
||||
frustum[2*4+2] = -(farVal + nearVal) / (farVal - nearVal);
|
||||
frustum[2*4+3] = float(-1);
|
||||
|
||||
frustum[3*4+0] = float(0);
|
||||
frustum[3*4+1] = float(0);
|
||||
frustum[3*4+2] = -(float(2) * farVal * nearVal) / (farVal - nearVal);
|
||||
frustum[3*4+3] = float(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void b3Matrix4x4Mul(GLfloat aIn[4][4], GLfloat bIn[4][4], GLfloat result[4][4])
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
for (int i=0;i<4;i++)
|
||||
result[j][i] = aIn[0][i] * bIn[j][0] + aIn[1][i] * bIn[j][1] + aIn[2][i] * bIn[j][2] + aIn[3][i] * bIn[j][3];
|
||||
}
|
||||
|
||||
static void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16])
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
for (int i=0;i<4;i++)
|
||||
result[j*4+i] = aIn[0*4+i] * bIn[j*4+0] + aIn[1*4+i] * bIn[j*4+1] + aIn[2*4+i] * bIn[j*4+2] + aIn[3*4+i] * bIn[j*4+3];
|
||||
}
|
||||
|
||||
|
||||
static void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4])
|
||||
{
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
{
|
||||
if (i==j)
|
||||
{
|
||||
result[i][j] = value;
|
||||
} else
|
||||
{
|
||||
result[i][j] = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, GLfloat result[4][4])
|
||||
{
|
||||
b3CreateDiagonalMatrix(1.f,result);
|
||||
|
||||
result[0][0] = 2.f / (right - left);
|
||||
result[1][1] = 2.f / (top - bottom);
|
||||
result[2][2] = - 2.f / (zFar - zNear);
|
||||
result[3][0] = - (right + left) / (right - left);
|
||||
result[3][1] = - (top + bottom) / (top - bottom);
|
||||
result[3][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
}
|
||||
|
||||
static void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, GLfloat result[16])
|
||||
{
|
||||
b3Vector3 f = (center - eye).normalized();
|
||||
b3Vector3 u = up.normalized();
|
||||
b3Vector3 s = (f.cross(u)).normalized();
|
||||
u = s.cross(f);
|
||||
|
||||
result[0*4+0] = s.x;
|
||||
result[1*4+0] = s.y;
|
||||
result[2*4+0] = s.z;
|
||||
|
||||
result[0*4+1] = u.x;
|
||||
result[1*4+1] = u.y;
|
||||
result[2*4+1] = u.z;
|
||||
|
||||
result[0*4+2] =-f.x;
|
||||
result[1*4+2] =-f.y;
|
||||
result[2*4+2] =-f.z;
|
||||
|
||||
result[0*4+3] = 0.f;
|
||||
result[1*4+3] = 0.f;
|
||||
result[2*4+3] = 0.f;
|
||||
|
||||
result[3*4+0] = -s.dot(eye);
|
||||
result[3*4+1] = -u.dot(eye);
|
||||
result[3*4+2] = f.dot(eye);
|
||||
result[3*4+3] = 1.f;
|
||||
}
|
||||
|
||||
|
||||
void GLInstancingRenderer::resize(int width, int height)
|
||||
@@ -1079,188 +817,53 @@ void GLInstancingRenderer::resize(int width, int height)
|
||||
m_screenHeight = height;
|
||||
}
|
||||
|
||||
|
||||
const CommonCameraInterface* GLInstancingRenderer::getActiveCamera() const
|
||||
{
|
||||
return &m_data->m_defaultCamera;
|
||||
}
|
||||
|
||||
CommonCameraInterface* GLInstancingRenderer::getActiveCamera()
|
||||
{
|
||||
return &m_data->m_defaultCamera;
|
||||
}
|
||||
|
||||
|
||||
void GLInstancingRenderer::setActiveCamera(CommonCameraInterface* cam)
|
||||
{
|
||||
b3Assert(0);//not supported yet
|
||||
}
|
||||
|
||||
|
||||
void GLInstancingRenderer::updateCamera(int upAxis)
|
||||
{
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
m_upAxis = upAxis;
|
||||
int m_forwardAxis(-1);
|
||||
switch (upAxis)
|
||||
{
|
||||
case 1:
|
||||
m_forwardAxis = 2;
|
||||
m_data->m_cameraUp = b3MakeVector3(0,1,0);
|
||||
gLightPos = b3MakeVector3(-50.f,100,30);
|
||||
gLightPos = b3MakeVector3(-50.f,100,30);
|
||||
break;
|
||||
case 2:
|
||||
m_forwardAxis = 1;
|
||||
m_data->m_cameraUp = b3MakeVector3(0,0,1);
|
||||
gLightPos = b3MakeVector3(-50.f,30,100);
|
||||
break;
|
||||
default:
|
||||
b3Assert(0);
|
||||
};
|
||||
|
||||
m_data->m_defaultCamera.setCameraUpAxis(upAxis);
|
||||
m_data->m_defaultCamera.setAspectRatio((float)m_screenWidth/(float)m_screenHeight);
|
||||
m_data->m_defaultCamera.update();
|
||||
|
||||
float m_frustumZNear=0.01;
|
||||
float m_frustumZFar=1000.f;
|
||||
|
||||
|
||||
// m_azi=m_azi+0.01;
|
||||
b3Scalar rele = m_data->m_ele * b3Scalar(0.01745329251994329547);// rads per deg
|
||||
b3Scalar razi = m_data->m_azi * b3Scalar(0.01745329251994329547);// rads per deg
|
||||
|
||||
|
||||
b3Quaternion rot(m_data->m_cameraUp,razi);
|
||||
|
||||
b3Vector3 eyePos = b3MakeVector3(0,0,0);
|
||||
eyePos[m_forwardAxis] = -m_data->m_cameraDistance;
|
||||
|
||||
b3Vector3 forward = b3MakeVector3(eyePos[0],eyePos[1],eyePos[2]);
|
||||
if (forward.length2() < B3_EPSILON)
|
||||
{
|
||||
forward.setValue(1.f,0.f,0.f);
|
||||
}
|
||||
b3Vector3 right = m_data->m_cameraUp.cross(forward);
|
||||
b3Quaternion roll(right,-rele);
|
||||
|
||||
eyePos = b3Matrix3x3(rot) * b3Matrix3x3(roll) * eyePos;
|
||||
|
||||
m_data->m_cameraPosition[0] = eyePos.x;
|
||||
m_data->m_cameraPosition[1] = eyePos.y;
|
||||
m_data->m_cameraPosition[2] = eyePos.z;
|
||||
m_data->m_cameraPosition += m_data->m_cameraTargetPosition;
|
||||
|
||||
if (m_screenWidth == 0 && m_screenHeight == 0)
|
||||
return;
|
||||
|
||||
b3Scalar aspect;
|
||||
b3Vector3 extents;
|
||||
|
||||
aspect = m_screenWidth / (b3Scalar)m_screenHeight;
|
||||
extents.setValue(aspect * 1.0f, 1.0f,0);
|
||||
|
||||
|
||||
if (m_screenWidth > m_screenHeight)
|
||||
{
|
||||
b3CreateFrustum(-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar,m_data->m_projectionMatrix);
|
||||
} else
|
||||
{
|
||||
b3CreateFrustum(-aspect * m_frustumZNear, aspect * m_frustumZNear, -m_frustumZNear, m_frustumZNear, m_frustumZNear, m_frustumZFar,m_data->m_projectionMatrix);
|
||||
}
|
||||
|
||||
b3CreateLookAt(m_data->m_cameraPosition,m_data->m_cameraTargetPosition,m_data->m_cameraUp,m_data->m_viewMatrix);
|
||||
|
||||
m_data->m_defaultCamera.getCameraProjectionMatrix(m_data->m_projectionMatrix);
|
||||
m_data->m_defaultCamera.getCameraViewMatrix(m_data->m_viewMatrix);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GLInstancingRenderer::getCameraPosition(float cameraPos[4])
|
||||
{
|
||||
cameraPos[0] = m_data->m_cameraPosition[0];
|
||||
cameraPos[1] = m_data->m_cameraPosition[1];
|
||||
cameraPos[2] = m_data->m_cameraPosition[2];
|
||||
cameraPos[3] = 1.f;
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::setCameraDistance(float dist)
|
||||
{
|
||||
m_data->m_cameraDistance = dist;
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::setCameraYaw(float yaw)
|
||||
{
|
||||
m_data->m_ele = yaw;
|
||||
}
|
||||
void GLInstancingRenderer::setCameraPitch(float pitch)
|
||||
{
|
||||
m_data->m_azi = pitch;
|
||||
}
|
||||
|
||||
float GLInstancingRenderer::getCameraYaw() const
|
||||
{
|
||||
return m_data->m_ele;
|
||||
}
|
||||
float GLInstancingRenderer::getCameraPitch() const
|
||||
{
|
||||
return m_data->m_azi;
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::setCameraTargetPosition(float x, float y, float z)
|
||||
{
|
||||
m_data->m_cameraTargetPosition = b3MakeVector3(x,y,z);
|
||||
}
|
||||
void GLInstancingRenderer::setCameraTargetPosition(float cameraPos[4])
|
||||
{
|
||||
setCameraTargetPosition(cameraPos[0],cameraPos[1],cameraPos[2]);
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::getCameraTargetPosition(float cameraPos[4]) const
|
||||
{
|
||||
cameraPos[0] = m_data->m_cameraTargetPosition.x;
|
||||
cameraPos[1] = m_data->m_cameraTargetPosition.y;
|
||||
cameraPos[2] = m_data->m_cameraTargetPosition.z;
|
||||
}
|
||||
|
||||
|
||||
float GLInstancingRenderer::getCameraDistance() const
|
||||
{
|
||||
return m_data->m_cameraDistance;
|
||||
}
|
||||
|
||||
|
||||
void GLInstancingRenderer::getMouseDirection(float* dir, int x, int y)
|
||||
{
|
||||
float top = 1.f;
|
||||
float bottom = -1.f;
|
||||
float nearPlane = 1.f;
|
||||
float tanFov = (top-bottom)*0.5f / nearPlane;
|
||||
float fov = b3Scalar(2.0) * b3Atan(tanFov);
|
||||
|
||||
b3Vector3 rayFrom = m_data->m_cameraPosition;
|
||||
b3Vector3 rayForward = (m_data->m_cameraTargetPosition-m_data->m_cameraPosition);
|
||||
rayForward.normalize();
|
||||
float farPlane = 10000.f;
|
||||
rayForward*= farPlane;
|
||||
|
||||
// b3Vector3 rightOffset;
|
||||
b3Vector3 vertical = m_data->m_cameraUp;
|
||||
|
||||
b3Vector3 hor;
|
||||
hor = rayForward.cross(vertical);
|
||||
hor.normalize();
|
||||
vertical = hor.cross(rayForward);
|
||||
vertical.normalize();
|
||||
|
||||
float tanfov = tanf(0.5f*fov);
|
||||
|
||||
|
||||
hor *= 2.f * farPlane * tanfov;
|
||||
vertical *= 2.f * farPlane * tanfov;
|
||||
|
||||
b3Scalar aspect;
|
||||
|
||||
aspect = m_screenWidth / (b3Scalar)m_screenHeight;
|
||||
|
||||
hor*=aspect;
|
||||
|
||||
|
||||
b3Vector3 rayToCenter = rayFrom + rayForward;
|
||||
b3Vector3 dHor = hor * 1.f/float(m_screenWidth);
|
||||
b3Vector3 dVert = vertical * 1.f/float(m_screenHeight);
|
||||
|
||||
|
||||
b3Vector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical;
|
||||
rayTo += b3Scalar(x) * dHor;
|
||||
rayTo -= b3Scalar(y) * dVert;
|
||||
|
||||
dir[0] = rayTo[0];
|
||||
dir[1] = rayTo[1];
|
||||
dir[2] = rayTo[2];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
@@ -1560,6 +1163,119 @@ struct PointerCaster
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
static void b3CreateFrustum(
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
float frustum[16])
|
||||
{
|
||||
|
||||
frustum[0*4+0] = (float(2) * nearVal) / (right - left);
|
||||
frustum[0*4+1] = float(0);
|
||||
frustum[0*4+2] = float(0);
|
||||
frustum[0*4+3] = float(0);
|
||||
|
||||
frustum[1*4+0] = float(0);
|
||||
frustum[1*4+1] = (float(2) * nearVal) / (top - bottom);
|
||||
frustum[1*4+2] = float(0);
|
||||
frustum[1*4+3] = float(0);
|
||||
|
||||
frustum[2*4+0] = (right + left) / (right - left);
|
||||
frustum[2*4+1] = (top + bottom) / (top - bottom);
|
||||
frustum[2*4+2] = -(farVal + nearVal) / (farVal - nearVal);
|
||||
frustum[2*4+3] = float(-1);
|
||||
|
||||
frustum[3*4+0] = float(0);
|
||||
frustum[3*4+1] = float(0);
|
||||
frustum[3*4+2] = -(float(2) * farVal * nearVal) / (farVal - nearVal);
|
||||
frustum[3*4+3] = float(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void b3Matrix4x4Mul(GLfloat aIn[4][4], GLfloat bIn[4][4], GLfloat result[4][4])
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
for (int i=0;i<4;i++)
|
||||
result[j][i] = aIn[0][i] * bIn[j][0] + aIn[1][i] * bIn[j][1] + aIn[2][i] * bIn[j][2] + aIn[3][i] * bIn[j][3];
|
||||
}
|
||||
|
||||
static void b3Matrix4x4Mul16(GLfloat aIn[16], GLfloat bIn[16], GLfloat result[16])
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
for (int i=0;i<4;i++)
|
||||
result[j*4+i] = aIn[0*4+i] * bIn[j*4+0] + aIn[1*4+i] * bIn[j*4+1] + aIn[2*4+i] * bIn[j*4+2] + aIn[3*4+i] * bIn[j*4+3];
|
||||
}
|
||||
|
||||
|
||||
static void b3CreateDiagonalMatrix(GLfloat value, GLfloat result[4][4])
|
||||
{
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
for (int j=0;j<4;j++)
|
||||
{
|
||||
if (i==j)
|
||||
{
|
||||
result[i][j] = value;
|
||||
} else
|
||||
{
|
||||
result[i][j] = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void b3CreateOrtho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, GLfloat result[4][4])
|
||||
{
|
||||
b3CreateDiagonalMatrix(1.f,result);
|
||||
|
||||
result[0][0] = 2.f / (right - left);
|
||||
result[1][1] = 2.f / (top - bottom);
|
||||
result[2][2] = - 2.f / (zFar - zNear);
|
||||
result[3][0] = - (right + left) / (right - left);
|
||||
result[3][1] = - (top + bottom) / (top - bottom);
|
||||
result[3][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
}
|
||||
|
||||
static void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,const b3Vector3& up, GLfloat result[16])
|
||||
{
|
||||
b3Vector3 f = (center - eye).normalized();
|
||||
b3Vector3 u = up.normalized();
|
||||
b3Vector3 s = (f.cross(u)).normalized();
|
||||
u = s.cross(f);
|
||||
|
||||
result[0*4+0] = s.x;
|
||||
result[1*4+0] = s.y;
|
||||
result[2*4+0] = s.z;
|
||||
|
||||
result[0*4+1] = u.x;
|
||||
result[1*4+1] = u.y;
|
||||
result[2*4+1] = u.z;
|
||||
|
||||
result[0*4+2] =-f.x;
|
||||
result[1*4+2] =-f.y;
|
||||
result[2*4+2] =-f.z;
|
||||
|
||||
result[0*4+3] = 0.f;
|
||||
result[1*4+3] = 0.f;
|
||||
result[2*4+3] = 0.f;
|
||||
|
||||
result[3*4+0] = -s.dot(eye);
|
||||
result[3*4+1] = -u.dot(eye);
|
||||
result[3*4+2] = f.dot(eye);
|
||||
result[3*4+3] = 1.f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
||||
{
|
||||
|
||||
@@ -1644,7 +1360,9 @@ void GLInstancingRenderer::renderSceneInternal(int renderMode)
|
||||
b3CreateOrtho(-shadowMapWorldSize,shadowMapWorldSize,-shadowMapWorldSize,shadowMapWorldSize,1,300,depthProjectionMatrix);//-14,14,-14,14,1,200, depthProjectionMatrix);
|
||||
float depthViewMatrix[4][4];
|
||||
b3Vector3 center = b3MakeVector3(0,0,0);
|
||||
b3Vector3 up =b3MakeVector3(0,1,0);
|
||||
float upf[3];
|
||||
m_data->m_defaultCamera.getCameraUpVector(upf);
|
||||
b3Vector3 up = b3MakeVector3(upf[0],upf[1],upf[2]);
|
||||
b3CreateLookAt(gLightPos,center,up,&depthViewMatrix[0][0]);
|
||||
//b3CreateLookAt(lightPos,m_data->m_cameraTargetPosition,b3Vector3(0,1,0),(float*)depthModelViewMatrix2);
|
||||
|
||||
@@ -1912,18 +1630,3 @@ void GLInstancingRenderer::enableShadowMap()
|
||||
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::getCameraViewMatrix(float viewMat[16]) const
|
||||
{
|
||||
for (int i=0;i<16;i++)
|
||||
{
|
||||
viewMat[i] = m_data->m_viewMatrix[i];
|
||||
}
|
||||
|
||||
}
|
||||
void GLInstancingRenderer::getCameraProjectionMatrix(float projMat[16]) const
|
||||
{
|
||||
for (int i=0;i<16;i++)
|
||||
{
|
||||
projMat[i] = m_data->m_projectionMatrix[i];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user