more example refactoring
This commit is contained in:
@@ -15,7 +15,7 @@ subject to the following restrictions:
|
|||||||
#ifndef BENCHMARK_EXAMPLE_H
|
#ifndef BENCHMARK_EXAMPLE_H
|
||||||
#define BENCHMARK_EXAMPLE_H
|
#define BENCHMARK_EXAMPLE_H
|
||||||
|
|
||||||
struct ExampleInterface* BenchmarkCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
class ExampleInterface* BenchmarkCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
33
examples/CommonInterfaces/CommonCameraInterface.h
Normal file
33
examples/CommonInterfaces/CommonCameraInterface.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef COMMON_CAMERA_INTERFACE_H
|
||||||
|
#define COMMON_CAMERA_INTERFACE_H
|
||||||
|
|
||||||
|
struct CommonCameraInterface
|
||||||
|
{
|
||||||
|
virtual void getCameraProjectionMatrix(float m[16])const = 0;
|
||||||
|
virtual void getCameraViewMatrix(float m[16]) const = 0;
|
||||||
|
|
||||||
|
virtual void getCameraTargetPosition(float pos[3]) const = 0;
|
||||||
|
virtual void getCameraPosition(float pos[3]) const = 0;
|
||||||
|
|
||||||
|
virtual void setCameraTargetPosition(float x,float y,float z) = 0;
|
||||||
|
virtual void setCameraDistance(float dist) = 0;
|
||||||
|
virtual float getCameraDistance() const = 0;
|
||||||
|
|
||||||
|
virtual void setCameraUpVector(float x,float y, float z) = 0;
|
||||||
|
virtual void getCameraUpVector(float up[3]) const = 0;
|
||||||
|
///the setCameraUpAxis will call the 'setCameraUpVector' and 'setCameraForwardVector'
|
||||||
|
virtual void setCameraUpAxis(int axis) = 0;
|
||||||
|
virtual int getCameraUpAxis() const = 0;
|
||||||
|
|
||||||
|
virtual void setCameraYaw(float yaw) = 0;
|
||||||
|
virtual float getCameraYaw() const = 0;
|
||||||
|
|
||||||
|
virtual void setCameraPitch(float pitch) = 0;
|
||||||
|
virtual float getCameraPitch() const = 0;
|
||||||
|
|
||||||
|
virtual void setAspectRatio(float ratio) = 0;
|
||||||
|
virtual float getAspectRatio() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //COMMON_CAMERA_INTERFACE_H
|
||||||
|
|
||||||
@@ -1,6 +1,13 @@
|
|||||||
#ifndef COMMON_GRAPHICS_APP_H
|
#ifndef COMMON_GRAPHICS_APP_H
|
||||||
#define COMMON_GRAPHICS_APP_H
|
#define COMMON_GRAPHICS_APP_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "Bullet3Common/b3Vector3.h"
|
||||||
|
#include "CommonRenderInterface.h"
|
||||||
|
#include "CommonWindowInterface.h"
|
||||||
|
#include "CommonCameraInterface.h"
|
||||||
|
|
||||||
struct DrawGridData
|
struct DrawGridData
|
||||||
{
|
{
|
||||||
int gridSize;
|
int gridSize;
|
||||||
@@ -22,22 +29,39 @@ struct DrawGridData
|
|||||||
|
|
||||||
struct CommonGraphicsApp
|
struct CommonGraphicsApp
|
||||||
{
|
{
|
||||||
|
class b3gWindowInterface* m_window;
|
||||||
|
struct CommonRenderInterface* m_renderer;
|
||||||
|
struct CommonParameterInterface* m_parameterInterface;
|
||||||
|
struct Common2dCanvasInterface* m_2dCanvasInterface;
|
||||||
|
|
||||||
|
bool m_leftMouseButton;
|
||||||
|
bool m_middleMouseButton;
|
||||||
|
bool m_rightMouseButton;
|
||||||
|
float m_wheelMultiplier;
|
||||||
|
float m_mouseMoveMultiplier;
|
||||||
|
float m_mouseXpos;
|
||||||
|
float m_mouseYpos;
|
||||||
|
bool m_mouseInitialized;
|
||||||
|
|
||||||
CommonGraphicsApp()
|
CommonGraphicsApp()
|
||||||
:m_window(0),
|
:m_window(0),
|
||||||
m_renderer(0),
|
m_renderer(0),
|
||||||
m_parameterInterface(0),
|
m_parameterInterface(0),
|
||||||
m_2dCanvasInterface(0)
|
m_2dCanvasInterface(0),
|
||||||
|
m_leftMouseButton(false),
|
||||||
|
m_middleMouseButton(false),
|
||||||
|
m_rightMouseButton(false),
|
||||||
|
m_wheelMultiplier(0.01f),
|
||||||
|
m_mouseMoveMultiplier(0.4f),
|
||||||
|
m_mouseXpos(0.f),
|
||||||
|
m_mouseYpos(0.f),
|
||||||
|
m_mouseInitialized(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual ~CommonGraphicsApp()
|
virtual ~CommonGraphicsApp()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class b3gWindowInterface* m_window;
|
|
||||||
struct CommonRenderInterface* m_renderer;
|
|
||||||
struct CommonParameterInterface* m_parameterInterface;
|
|
||||||
struct Common2dCanvasInterface* m_2dCanvasInterface;
|
|
||||||
|
|
||||||
virtual void drawGrid(DrawGridData data=DrawGridData()) = 0;
|
virtual void drawGrid(DrawGridData data=DrawGridData()) = 0;
|
||||||
virtual void setUpAxis(int axis) = 0;
|
virtual void setUpAxis(int axis) = 0;
|
||||||
virtual int getUpAxis() const = 0;
|
virtual int getUpAxis() const = 0;
|
||||||
@@ -48,6 +72,155 @@ struct CommonGraphicsApp
|
|||||||
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)=0;
|
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ)=0;
|
||||||
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10)=0;
|
virtual int registerGraphicsSphereShape(float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10)=0;
|
||||||
virtual void registerGrid(int xres, int yres, float color0[4], float color1[4])=0;
|
virtual void registerGrid(int xres, int yres, float color0[4], float color1[4])=0;
|
||||||
|
|
||||||
|
void defaultMouseButtonCallback( 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 defaultMouseMoveCallback( float x, float y)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (m_window && m_renderer)
|
||||||
|
{
|
||||||
|
CommonCameraInterface* camera = m_renderer->getActiveCamera();
|
||||||
|
|
||||||
|
bool isAltPressed = m_window->isModifiedKeyPressed(B3G_ALT);
|
||||||
|
bool isControlPressed = m_window->isModifiedKeyPressed(B3G_CONTROL);
|
||||||
|
|
||||||
|
|
||||||
|
if (isAltPressed || isControlPressed)
|
||||||
|
{
|
||||||
|
float xDelta = x-m_mouseXpos;
|
||||||
|
float yDelta = y-m_mouseYpos;
|
||||||
|
float cameraDistance = camera->getCameraDistance();
|
||||||
|
float pitch = camera->getCameraPitch();
|
||||||
|
float yaw = camera->getCameraYaw();
|
||||||
|
|
||||||
|
float targPos[3];
|
||||||
|
float camPos[3];
|
||||||
|
|
||||||
|
camera->getCameraTargetPosition(targPos);
|
||||||
|
camera->getCameraPosition(camPos);
|
||||||
|
|
||||||
|
b3Vector3 cameraPosition = b3MakeVector3(b3Scalar(camPos[0]),
|
||||||
|
b3Scalar(camPos[1]),
|
||||||
|
b3Scalar(camPos[2]));
|
||||||
|
|
||||||
|
b3Vector3 cameraTargetPosition = b3MakeVector3( b3Scalar(targPos[0]),
|
||||||
|
b3Scalar(targPos[1]),
|
||||||
|
b3Scalar(targPos[2]));
|
||||||
|
b3Vector3 cameraUp = b3MakeVector3(0,0,0);
|
||||||
|
cameraUp[camera->getCameraUpAxis()] = 1.f;
|
||||||
|
|
||||||
|
if (m_leftMouseButton)
|
||||||
|
{
|
||||||
|
// if (b3Fabs(xDelta)>b3Fabs(yDelta))
|
||||||
|
// {
|
||||||
|
pitch -= xDelta*m_mouseMoveMultiplier;
|
||||||
|
// } else
|
||||||
|
// {
|
||||||
|
yaw += yDelta*m_mouseMoveMultiplier;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_middleMouseButton)
|
||||||
|
{
|
||||||
|
cameraTargetPosition += cameraUp * yDelta*0.01;
|
||||||
|
|
||||||
|
|
||||||
|
b3Vector3 fwd = cameraTargetPosition-cameraPosition;
|
||||||
|
b3Vector3 side = cameraUp.cross(fwd);
|
||||||
|
side.normalize();
|
||||||
|
cameraTargetPosition += side * xDelta*0.01;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (m_rightMouseButton)
|
||||||
|
{
|
||||||
|
cameraDistance -= xDelta*0.01f;
|
||||||
|
cameraDistance -= yDelta*0.01f;
|
||||||
|
if (cameraDistance<1)
|
||||||
|
cameraDistance=1;
|
||||||
|
if (cameraDistance>1000)
|
||||||
|
cameraDistance=1000;
|
||||||
|
}
|
||||||
|
camera->setCameraDistance(cameraDistance);
|
||||||
|
camera->setCameraPitch(pitch);
|
||||||
|
camera->setCameraYaw(yaw);
|
||||||
|
camera->setCameraTargetPosition(cameraTargetPosition[0],cameraTargetPosition[1],cameraTargetPosition[2]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}//m_window && m_renderer
|
||||||
|
|
||||||
|
m_mouseXpos = x;
|
||||||
|
m_mouseYpos = y;
|
||||||
|
m_mouseInitialized = true;
|
||||||
|
}
|
||||||
|
// void defaultKeyboardCallback(int key, int state)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
void defaultWheelCallback( float deltax, float deltay)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (m_renderer)
|
||||||
|
{
|
||||||
|
b3Vector3 cameraTargetPosition, cameraPosition, cameraUp = b3MakeVector3(0,0,0);
|
||||||
|
cameraUp[getUpAxis()] = 1;
|
||||||
|
CommonCameraInterface* camera = m_renderer->getActiveCamera();
|
||||||
|
|
||||||
|
camera->getCameraPosition(cameraPosition);
|
||||||
|
camera->getCameraTargetPosition(cameraTargetPosition);
|
||||||
|
|
||||||
|
if (!m_leftMouseButton)
|
||||||
|
{
|
||||||
|
|
||||||
|
float cameraDistance = camera->getCameraDistance();
|
||||||
|
if (deltay<0 || cameraDistance>1)
|
||||||
|
{
|
||||||
|
cameraDistance -= deltay*0.1f;
|
||||||
|
if (cameraDistance<1)
|
||||||
|
cameraDistance=1;
|
||||||
|
camera->setCameraDistance(cameraDistance);
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
|
||||||
|
b3Vector3 fwd = cameraTargetPosition-cameraPosition;
|
||||||
|
fwd.normalize();
|
||||||
|
cameraTargetPosition += fwd*deltay*m_wheelMultiplier;//todo: expose it in the GUI?
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if (b3Fabs(deltax)>b3Fabs(deltay))
|
||||||
|
{
|
||||||
|
b3Vector3 fwd = cameraTargetPosition-cameraPosition;
|
||||||
|
b3Vector3 side = cameraUp.cross(fwd);
|
||||||
|
side.normalize();
|
||||||
|
cameraTargetPosition += side * deltax*m_wheelMultiplier;
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
cameraTargetPosition -= cameraUp * deltay*m_wheelMultiplier;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
camera->setCameraTargetPosition(cameraTargetPosition[0],cameraTargetPosition[1],cameraTargetPosition[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "CommonRenderInterface.h"
|
#include "CommonRenderInterface.h"
|
||||||
#include "CommonGraphicsAppInterface.h"
|
#include "CommonGraphicsAppInterface.h"
|
||||||
#include "CommonWindowInterface.h"
|
#include "CommonWindowInterface.h"
|
||||||
|
#include "CommonCameraInterface.h"
|
||||||
|
|
||||||
struct CommonMultiBodyBase : public ExampleInterface
|
struct CommonMultiBodyBase : public ExampleInterface
|
||||||
{
|
{
|
||||||
@@ -181,8 +182,8 @@ struct CommonMultiBodyBase : public ExampleInterface
|
|||||||
float fov = btScalar(2.0) * btAtan(tanFov);
|
float fov = btScalar(2.0) * btAtan(tanFov);
|
||||||
|
|
||||||
btVector3 camPos,camTarget;
|
btVector3 camPos,camTarget;
|
||||||
renderer->getCameraPosition(camPos);
|
renderer->getActiveCamera()->getCameraPosition(camPos);
|
||||||
renderer->getCameraTargetPosition(camTarget);
|
renderer->getActiveCamera()->getCameraTargetPosition(camTarget);
|
||||||
|
|
||||||
btVector3 rayFrom = camPos;
|
btVector3 rayFrom = camPos;
|
||||||
btVector3 rayForward = (camTarget-camPos);
|
btVector3 rayForward = (camTarget-camPos);
|
||||||
@@ -240,7 +241,7 @@ struct CommonMultiBodyBase : public ExampleInterface
|
|||||||
|
|
||||||
btVector3 rayTo = getRayTo(int(x), int(y));
|
btVector3 rayTo = getRayTo(int(x), int(y));
|
||||||
btVector3 rayFrom;
|
btVector3 rayFrom;
|
||||||
renderer->getCameraPosition(rayFrom);
|
renderer->getActiveCamera()->getCameraPosition(rayFrom);
|
||||||
movePickedBody(rayFrom,rayTo);
|
movePickedBody(rayFrom,rayTo);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -264,7 +265,7 @@ struct CommonMultiBodyBase : public ExampleInterface
|
|||||||
if(button==0 && (!window->isModifiedKeyPressed(B3G_ALT) && !window->isModifiedKeyPressed(B3G_CONTROL) ))
|
if(button==0 && (!window->isModifiedKeyPressed(B3G_ALT) && !window->isModifiedKeyPressed(B3G_CONTROL) ))
|
||||||
{
|
{
|
||||||
btVector3 camPos;
|
btVector3 camPos;
|
||||||
renderer->getCameraPosition(camPos);
|
renderer->getActiveCamera()->getCameraPosition(camPos);
|
||||||
|
|
||||||
btVector3 rayFrom = camPos;
|
btVector3 rayFrom = camPos;
|
||||||
btVector3 rayTo = getRayTo(int(x),int(y));
|
btVector3 rayTo = getRayTo(int(x),int(y));
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef COMMON_RENDER_INTERFACE_H
|
#ifndef COMMON_RENDER_INTERFACE_H
|
||||||
#define COMMON_RENDER_INTERFACE_H
|
#define COMMON_RENDER_INTERFACE_H
|
||||||
|
|
||||||
|
struct CommonCameraInterface;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
B3_GL_TRIANGLES = 1,
|
B3_GL_TRIANGLES = 1,
|
||||||
@@ -20,20 +22,10 @@ struct CommonRenderInterface
|
|||||||
virtual void init()=0;
|
virtual void init()=0;
|
||||||
virtual void updateCamera(int upAxis)=0;
|
virtual void updateCamera(int upAxis)=0;
|
||||||
virtual void removeAllInstances() = 0;
|
virtual void removeAllInstances() = 0;
|
||||||
virtual void setCameraDistance(float dist) = 0;
|
|
||||||
virtual void setCameraPitch(float pitch) = 0;
|
|
||||||
virtual void setCameraTargetPosition(float x, float y, float z)=0;
|
|
||||||
|
|
||||||
|
virtual const CommonCameraInterface* getActiveCamera() const =0;
|
||||||
virtual void getCameraPosition(float cameraPos[4])=0;
|
virtual CommonCameraInterface* getActiveCamera()=0;
|
||||||
virtual void getCameraPosition(double cameraPos[4])=0;
|
virtual void setActiveCamera(CommonCameraInterface* cam)=0;
|
||||||
|
|
||||||
virtual void setCameraTargetPosition(float cameraPos[4])=0;
|
|
||||||
virtual void getCameraTargetPosition(float cameraPos[4]) const=0;
|
|
||||||
virtual void getCameraTargetPosition(double cameraPos[4]) const=0;
|
|
||||||
|
|
||||||
virtual void getCameraViewMatrix(float viewMat[16]) const=0;
|
|
||||||
virtual void getCameraProjectionMatrix(float projMat[16]) const=0;
|
|
||||||
|
|
||||||
virtual void renderScene()=0;
|
virtual void renderScene()=0;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "ExampleInterface.h"
|
#include "ExampleInterface.h"
|
||||||
#include "CommonGUIHelperInterface.h"
|
#include "CommonGUIHelperInterface.h"
|
||||||
#include "CommonRenderInterface.h"
|
#include "CommonRenderInterface.h"
|
||||||
|
#include "CommonCameraInterface.h"
|
||||||
|
|
||||||
#include "CommonGraphicsAppInterface.h"
|
#include "CommonGraphicsAppInterface.h"
|
||||||
#include "CommonWindowInterface.h"
|
#include "CommonWindowInterface.h"
|
||||||
|
|
||||||
@@ -169,8 +171,9 @@ struct CommonRigidBodyBase : public ExampleInterface
|
|||||||
float fov = btScalar(2.0) * btAtan(tanFov);
|
float fov = btScalar(2.0) * btAtan(tanFov);
|
||||||
|
|
||||||
btVector3 camPos,camTarget;
|
btVector3 camPos,camTarget;
|
||||||
renderer->getCameraPosition(camPos);
|
|
||||||
renderer->getCameraTargetPosition(camTarget);
|
renderer->getActiveCamera()->getCameraPosition(camPos);
|
||||||
|
renderer->getActiveCamera()->getCameraTargetPosition(camTarget);
|
||||||
|
|
||||||
btVector3 rayFrom = camPos;
|
btVector3 rayFrom = camPos;
|
||||||
btVector3 rayForward = (camTarget-camPos);
|
btVector3 rayForward = (camTarget-camPos);
|
||||||
@@ -228,7 +231,7 @@ struct CommonRigidBodyBase : public ExampleInterface
|
|||||||
|
|
||||||
btVector3 rayTo = getRayTo(int(x), int(y));
|
btVector3 rayTo = getRayTo(int(x), int(y));
|
||||||
btVector3 rayFrom;
|
btVector3 rayFrom;
|
||||||
renderer->getCameraPosition(rayFrom);
|
renderer->getActiveCamera()->getCameraPosition(rayFrom);
|
||||||
movePickedBody(rayFrom,rayTo);
|
movePickedBody(rayFrom,rayTo);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -252,7 +255,7 @@ struct CommonRigidBodyBase : public ExampleInterface
|
|||||||
if(button==0 && (!window->isModifiedKeyPressed(B3G_ALT) && !window->isModifiedKeyPressed(B3G_CONTROL) ))
|
if(button==0 && (!window->isModifiedKeyPressed(B3G_ALT) && !window->isModifiedKeyPressed(B3G_CONTROL) ))
|
||||||
{
|
{
|
||||||
btVector3 camPos;
|
btVector3 camPos;
|
||||||
renderer->getCameraPosition(camPos);
|
renderer->getActiveCamera()->getCameraPosition(camPos);
|
||||||
|
|
||||||
btVector3 rayFrom = camPos;
|
btVector3 rayFrom = camPos;
|
||||||
btVector3 rayTo = getRayTo(int(x),int(y));
|
btVector3 rayTo = getRayTo(int(x),int(y));
|
||||||
|
|||||||
@@ -554,9 +554,9 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[])
|
|||||||
prevKeyboardCallback = s_window->getKeyboardCallback();
|
prevKeyboardCallback = s_window->getKeyboardCallback();
|
||||||
s_window->setKeyboardCallback(MyKeyboardCallback);
|
s_window->setKeyboardCallback(MyKeyboardCallback);
|
||||||
|
|
||||||
s_app->m_renderer->setCameraDistance(13);
|
s_app->m_renderer->getActiveCamera()->setCameraDistance(13);
|
||||||
s_app->m_renderer->setCameraPitch(0);
|
s_app->m_renderer->getActiveCamera()->setCameraPitch(0);
|
||||||
s_app->m_renderer->setCameraTargetPosition(0,0,0);
|
s_app->m_renderer->getActiveCamera()->setCameraTargetPosition(0,0,0);
|
||||||
|
|
||||||
b3SetCustomWarningMessageFunc(MyStatusBarWarning);
|
b3SetCustomWarningMessageFunc(MyStatusBarWarning);
|
||||||
b3SetCustomPrintfFunc(MyStatusBarPrintf);
|
b3SetCustomPrintfFunc(MyStatusBarPrintf);
|
||||||
@@ -701,7 +701,10 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
|||||||
dg.upAxis = s_app->getUpAxis();
|
dg.upAxis = s_app->getUpAxis();
|
||||||
|
|
||||||
{
|
{
|
||||||
BT_PROFILE("Update Camera");
|
BT_PROFILE("Update Camera and Light");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
s_instancingRenderer->updateCamera(dg.upAxis);
|
s_instancingRenderer->updateCamera(dg.upAxis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1305,7 +1305,7 @@ btRigidBody* ForkLiftDemo::localCreateRigidBody(btScalar mass, const btTransform
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExampleInterface* ForkLiftCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
ExampleInterface* ForkLiftCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||||
{
|
{
|
||||||
return new ForkLiftDemo(helper);
|
return new ForkLiftDemo(helper);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ subject to the following restrictions:
|
|||||||
#ifndef FORKLIFT_DEMO_H
|
#ifndef FORKLIFT_DEMO_H
|
||||||
#define FORKLIFT_DEMO_H
|
#define FORKLIFT_DEMO_H
|
||||||
|
|
||||||
struct ExampleInterface* ForkLiftCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
class ExampleInterface* ForkLiftCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||||
|
|
||||||
#endif // FORKLIFT_DEMO_H
|
#endif // FORKLIFT_DEMO_H
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ GyroscopicSetup::GyroscopicSetup(struct GUIHelperInterface* helper)
|
|||||||
|
|
||||||
void GyroscopicSetup::initPhysics()
|
void GyroscopicSetup::initPhysics()
|
||||||
{
|
{
|
||||||
m_guiHelper->setUpAxis(2);
|
m_guiHelper->setUpAxis(1);
|
||||||
createEmptyDynamicsWorld();
|
createEmptyDynamicsWorld();
|
||||||
m_dynamicsWorld->setGravity(btVector3(0, 0, 0));
|
m_dynamicsWorld->setGravity(btVector3(0, 0, 0));
|
||||||
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
||||||
@@ -91,7 +91,7 @@ void GyroscopicSetup::initPhysics()
|
|||||||
|
|
||||||
{
|
{
|
||||||
//btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(0.5)));
|
//btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(0.5)));
|
||||||
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0, 0, 1), 0);
|
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 0);
|
||||||
|
|
||||||
m_collisionShapes.push_back(groundShape);
|
m_collisionShapes.push_back(groundShape);
|
||||||
btTransform groundTransform;
|
btTransform groundTransform;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ subject to the following restrictions:
|
|||||||
#ifndef BSP_DEMO_H
|
#ifndef BSP_DEMO_H
|
||||||
#define BSP_DEMO_H
|
#define BSP_DEMO_H
|
||||||
|
|
||||||
struct ExampleInterface* ImportBspCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
class ExampleInterface* ImportBspCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||||
|
|
||||||
|
|
||||||
#endif //BSP_DEMO_H
|
#endif //BSP_DEMO_H
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ void ImportObjSetup::initPhysics()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExampleInterface* ImportObjCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
ExampleInterface* ImportObjCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||||
{
|
{
|
||||||
return new ImportObjSetup(helper);
|
return new ImportObjSetup(helper);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef IMPORT_OBJ_EXAMPLE_H
|
#ifndef IMPORT_OBJ_EXAMPLE_H
|
||||||
#define IMPORT_OBJ_EXAMPLE_H
|
#define IMPORT_OBJ_EXAMPLE_H
|
||||||
|
|
||||||
struct ExampleInterface* ImportObjCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
class ExampleInterface* ImportObjCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||||
|
|
||||||
|
|
||||||
#endif //IMPORT_OBJ_EXAMPLE_H
|
#endif //IMPORT_OBJ_EXAMPLE_H
|
||||||
|
|||||||
@@ -19,14 +19,13 @@ bool useShadowMap=true;//false;//true;
|
|||||||
int shadowMapWidth=8192;
|
int shadowMapWidth=8192;
|
||||||
int shadowMapHeight=8192;
|
int shadowMapHeight=8192;
|
||||||
float shadowMapWorldSize=100;
|
float shadowMapWorldSize=100;
|
||||||
float WHEEL_MULTIPLIER=0.01f;
|
|
||||||
float MOUSE_MOVE_MULTIPLIER = 0.4f;
|
|
||||||
#define MAX_POINTS_IN_BATCH 1024
|
#define MAX_POINTS_IN_BATCH 1024
|
||||||
#define MAX_LINES_IN_BATCH 1024
|
#define MAX_LINES_IN_BATCH 1024
|
||||||
|
|
||||||
|
|
||||||
#include "OpenGLInclude.h"
|
#include "OpenGLInclude.h"
|
||||||
#include "b3gWindowInterface.h"
|
#include "../CommonInterfaces/CommonWindowInterface.h"
|
||||||
//#include "Bullet3Common/b3MinMax.h"
|
//#include "Bullet3Common/b3MinMax.h"
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
@@ -141,20 +140,7 @@ extern int gShapeIndex;
|
|||||||
struct InternalDataRenderer : public GLInstanceRendererInternalData
|
struct InternalDataRenderer : public GLInstanceRendererInternalData
|
||||||
{
|
{
|
||||||
|
|
||||||
|
SimpleCamera m_defaultCamera;
|
||||||
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;
|
|
||||||
|
|
||||||
GLfloat m_projectionMatrix[16];
|
GLfloat m_projectionMatrix[16];
|
||||||
GLfloat m_viewMatrix[16];
|
GLfloat m_viewMatrix[16];
|
||||||
@@ -165,25 +151,10 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
|||||||
|
|
||||||
GLRenderToTexture* m_shadowMap;
|
GLRenderToTexture* m_shadowMap;
|
||||||
GLuint m_shadowTexture;
|
GLuint m_shadowTexture;
|
||||||
int m_altPressed;
|
|
||||||
int m_controlPressed;
|
|
||||||
|
|
||||||
InternalDataRenderer() :
|
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_shadowMap(0),
|
||||||
m_shadowTexture(0),
|
m_shadowTexture(0)
|
||||||
m_altPressed(0),
|
|
||||||
m_controlPressed(0)
|
|
||||||
{
|
{
|
||||||
//clear to zero to make it obvious if the matrix is used uninitialized
|
//clear to zero to make it obvious if the matrix is used uninitialized
|
||||||
for (int i=0;i<16;i++)
|
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;
|
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 linesShader; // The line renderer
|
||||||
static GLuint useShadowMapInstancingShader; // The shadow instancing 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)
|
void GLInstancingRenderer::resize(int width, int height)
|
||||||
@@ -1079,188 +817,53 @@ void GLInstancingRenderer::resize(int width, int height)
|
|||||||
m_screenHeight = 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)
|
void GLInstancingRenderer::updateCamera(int upAxis)
|
||||||
{
|
{
|
||||||
|
|
||||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||||
|
|
||||||
m_upAxis = upAxis;
|
m_upAxis = upAxis;
|
||||||
int m_forwardAxis(-1);
|
|
||||||
switch (upAxis)
|
switch (upAxis)
|
||||||
{
|
{
|
||||||
case 1:
|
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;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
m_forwardAxis = 1;
|
|
||||||
m_data->m_cameraUp = b3MakeVector3(0,0,1);
|
|
||||||
gLightPos = b3MakeVector3(-50.f,30,100);
|
gLightPos = b3MakeVector3(-50.f,30,100);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
b3Assert(0);
|
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;
|
m_data->m_defaultCamera.getCameraProjectionMatrix(m_data->m_projectionMatrix);
|
||||||
float m_frustumZFar=1000.f;
|
m_data->m_defaultCamera.getCameraViewMatrix(m_data->m_viewMatrix);
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
//#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)
|
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);
|
b3CreateOrtho(-shadowMapWorldSize,shadowMapWorldSize,-shadowMapWorldSize,shadowMapWorldSize,1,300,depthProjectionMatrix);//-14,14,-14,14,1,200, depthProjectionMatrix);
|
||||||
float depthViewMatrix[4][4];
|
float depthViewMatrix[4][4];
|
||||||
b3Vector3 center = b3MakeVector3(0,0,0);
|
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(gLightPos,center,up,&depthViewMatrix[0][0]);
|
||||||
//b3CreateLookAt(lightPos,m_data->m_cameraTargetPosition,b3Vector3(0,1,0),(float*)depthModelViewMatrix2);
|
//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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,12 +18,9 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||||
#include "../CommonInterfaces/CommonRenderInterface.h"
|
#include "../CommonInterfaces/CommonRenderInterface.h"
|
||||||
|
#include "SimpleCamera.h"
|
||||||
|
|
||||||
|
|
||||||
void b3DefaultMouseButtonCallback( int button, int state, float x, float y);
|
|
||||||
void b3DefaultMouseMoveCallback( float x, float y);
|
|
||||||
void b3DefaultKeyboardCallback(int key, int state);
|
|
||||||
void b3DefaultWheelCallback( float deltax, float deltay);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -48,6 +45,7 @@ class GLInstancingRenderer : public CommonRenderInterface
|
|||||||
void renderSceneInternal(int renderMode=B3_DEFAULT_RENDERMODE);
|
void renderSceneInternal(int renderMode=B3_DEFAULT_RENDERMODE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GLInstancingRenderer(int m_maxObjectCapacity, int maxShapeCapacityInBytes = 56*1024*1024);
|
GLInstancingRenderer(int m_maxObjectCapacity, int maxShapeCapacityInBytes = 56*1024*1024);
|
||||||
virtual ~GLInstancingRenderer();
|
virtual ~GLInstancingRenderer();
|
||||||
@@ -95,7 +93,6 @@ public:
|
|||||||
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
||||||
virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex);
|
virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex);
|
||||||
|
|
||||||
virtual void getMouseDirection(float* dir, int mouseX, int mouseY);
|
|
||||||
|
|
||||||
struct GLInstanceRendererInternalData* getInternalData();
|
struct GLInstanceRendererInternalData* getInternalData();
|
||||||
|
|
||||||
@@ -107,42 +104,9 @@ public:
|
|||||||
virtual void drawPoint(const double* position, const double color[4], double pointDrawSize=1);
|
virtual void drawPoint(const double* position, const double color[4], double pointDrawSize=1);
|
||||||
virtual void updateCamera(int upAxis=1);
|
virtual void updateCamera(int upAxis=1);
|
||||||
|
|
||||||
virtual void getCameraPosition(float cameraPos[4]);
|
virtual const CommonCameraInterface* getActiveCamera() const;
|
||||||
virtual void getCameraPosition(double cameraPos[4])
|
virtual CommonCameraInterface* getActiveCamera();
|
||||||
{
|
virtual void setActiveCamera(CommonCameraInterface* cam);
|
||||||
float campos[4];
|
|
||||||
getCameraPosition(campos);
|
|
||||||
cameraPos[0] = campos[0];
|
|
||||||
cameraPos[1] = campos[1];
|
|
||||||
cameraPos[2] = campos[2];
|
|
||||||
cameraPos[3] = campos[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setCameraDistance(float dist);
|
|
||||||
virtual float getCameraDistance() const;
|
|
||||||
|
|
||||||
//set the camera 'target'
|
|
||||||
virtual void setCameraTargetPosition(float x, float y, float z);
|
|
||||||
virtual void setCameraTargetPosition(float cameraPos[4]);
|
|
||||||
virtual void getCameraTargetPosition(float cameraPos[4]) const;
|
|
||||||
virtual void getCameraTargetPosition(double cameraPos[4]) const
|
|
||||||
{
|
|
||||||
float campos[4];
|
|
||||||
getCameraTargetPosition(campos);
|
|
||||||
cameraPos[0] = campos[0];
|
|
||||||
cameraPos[1] = campos[1];
|
|
||||||
cameraPos[2] = campos[2];
|
|
||||||
cameraPos[3] = campos[3];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setCameraYaw(float yaw);
|
|
||||||
virtual void setCameraPitch(float pitch);
|
|
||||||
virtual float getCameraYaw() const;
|
|
||||||
virtual float getCameraPitch() const;
|
|
||||||
|
|
||||||
virtual void getCameraViewMatrix(float viewMat[16]) const;
|
|
||||||
virtual void getCameraProjectionMatrix(float projMat[16]) const;
|
|
||||||
|
|
||||||
|
|
||||||
virtual void resize(int width, int height);
|
virtual void resize(int width, int height);
|
||||||
|
|||||||
@@ -149,6 +149,11 @@ void SimpleCamera::setCameraUpAxis(int upAxis)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SimpleCamera::getCameraUpAxis() const
|
||||||
|
{
|
||||||
|
return m_data->m_cameraUpAxis;
|
||||||
|
}
|
||||||
|
|
||||||
void SimpleCamera::update()
|
void SimpleCamera::update()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -230,6 +235,11 @@ void SimpleCamera::setCameraTargetPosition(float x,float y,float z)
|
|||||||
m_data->m_cameraTargetPosition.setValue(x,y,z);
|
m_data->m_cameraTargetPosition.setValue(x,y,z);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
float SimpleCamera::getCameraDistance() const
|
||||||
|
{
|
||||||
|
return m_data->m_cameraDistance;
|
||||||
|
}
|
||||||
|
|
||||||
void SimpleCamera::setCameraDistance(float dist)
|
void SimpleCamera::setCameraDistance(float dist)
|
||||||
{
|
{
|
||||||
m_data->m_cameraDistance = dist;
|
m_data->m_cameraDistance = dist;
|
||||||
@@ -241,12 +251,25 @@ void SimpleCamera::setCameraUpVector(float x,float y ,float z)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleCamera::getCameraUpVector(float up[3]) const
|
||||||
|
{
|
||||||
|
up[0] = float(m_data->m_cameraUp[0]);
|
||||||
|
up[1] = float(m_data->m_cameraUp[1]);
|
||||||
|
up[2] = float(m_data->m_cameraUp[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimpleCamera::setCameraYaw(float yaw)
|
void SimpleCamera::setCameraYaw(float yaw)
|
||||||
{
|
{
|
||||||
m_data->m_yaw = yaw;
|
m_data->m_yaw = yaw;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float SimpleCamera::getCameraYaw() const
|
||||||
|
{
|
||||||
|
return m_data->m_yaw;
|
||||||
|
}
|
||||||
|
|
||||||
void SimpleCamera::setCameraPitch(float pitch)
|
void SimpleCamera::setCameraPitch(float pitch)
|
||||||
{
|
{
|
||||||
m_data->m_pitch = pitch;
|
m_data->m_pitch = pitch;
|
||||||
@@ -258,3 +281,12 @@ void SimpleCamera::setAspectRatio(float ratio)
|
|||||||
m_data->m_aspect = ratio;
|
m_data->m_aspect = ratio;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float SimpleCamera::getCameraPitch() const
|
||||||
|
{
|
||||||
|
return m_data->m_pitch;
|
||||||
|
}
|
||||||
|
float SimpleCamera::getAspectRatio() const
|
||||||
|
{
|
||||||
|
return m_data->m_aspect;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
#ifndef SIMPLE_CAMERA_H
|
#ifndef SIMPLE_CAMERA_H
|
||||||
#define SIMPLE_CAMERA_H
|
#define SIMPLE_CAMERA_H
|
||||||
|
|
||||||
struct CommonCameraInterface
|
#include "../CommonInterfaces/CommonCameraInterface.h"
|
||||||
{
|
|
||||||
virtual void getCameraProjectionMatrix(float m[16])const = 0;
|
|
||||||
virtual void getCameraViewMatrix(float m[16]) const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SimpleCamera : public CommonCameraInterface
|
struct SimpleCamera : public CommonCameraInterface
|
||||||
{
|
{
|
||||||
@@ -23,14 +19,22 @@ struct SimpleCamera : public CommonCameraInterface
|
|||||||
|
|
||||||
virtual void setCameraTargetPosition(float x,float y,float z);
|
virtual void setCameraTargetPosition(float x,float y,float z);
|
||||||
virtual void setCameraDistance(float dist);
|
virtual void setCameraDistance(float dist);
|
||||||
|
virtual float getCameraDistance() const;
|
||||||
|
|
||||||
virtual void setCameraUpVector(float x,float y, float z);
|
virtual void setCameraUpVector(float x,float y, float z);
|
||||||
|
void getCameraUpVector(float up[3]) const;
|
||||||
///the setCameraUpAxis will call the 'setCameraUpVector' and 'setCameraForwardVector'
|
///the setCameraUpAxis will call the 'setCameraUpVector' and 'setCameraForwardVector'
|
||||||
virtual void setCameraUpAxis(int axis);
|
virtual void setCameraUpAxis(int axis);
|
||||||
|
virtual int getCameraUpAxis() const;
|
||||||
|
|
||||||
virtual void setCameraYaw(float yaw);
|
virtual void setCameraYaw(float yaw);
|
||||||
|
virtual float getCameraYaw() const;
|
||||||
|
|
||||||
virtual void setCameraPitch(float pitch);
|
virtual void setCameraPitch(float pitch);
|
||||||
virtual void setAspectRatio(float ratio);
|
virtual float getCameraPitch() const;
|
||||||
|
|
||||||
|
virtual void setAspectRatio(float ratio);
|
||||||
|
virtual float getAspectRatio() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //SIMPLE_CAMERA_H
|
#endif //SIMPLE_CAMERA_H
|
||||||
@@ -15,6 +15,19 @@ void SimpleOpenGL2Renderer::init()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CommonCameraInterface* SimpleOpenGL2Renderer::getActiveCamera() const
|
||||||
|
{
|
||||||
|
return &m_camera;
|
||||||
|
}
|
||||||
|
CommonCameraInterface* SimpleOpenGL2Renderer::getActiveCamera()
|
||||||
|
{
|
||||||
|
return &m_camera;
|
||||||
|
}
|
||||||
|
void SimpleOpenGL2Renderer::setActiveCamera(CommonCameraInterface* cam)
|
||||||
|
{
|
||||||
|
b3Assert(0);//not supported yet
|
||||||
|
}
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::updateCamera(int upAxis)
|
void SimpleOpenGL2Renderer::updateCamera(int upAxis)
|
||||||
{
|
{
|
||||||
float projection[16];
|
float projection[16];
|
||||||
@@ -43,56 +56,6 @@ void SimpleOpenGL2Renderer::removeAllInstances()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::setCameraDistance(float dist)
|
|
||||||
{
|
|
||||||
m_camera.setCameraDistance(dist);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::setCameraPitch(float pitch)
|
|
||||||
{
|
|
||||||
m_camera.setCameraPitch(pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::setCameraTargetPosition(float x, float y, float z)
|
|
||||||
{
|
|
||||||
m_camera.setCameraTargetPosition(x,y,z);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::getCameraPosition(float cameraPos[4])
|
|
||||||
{
|
|
||||||
float pos[3];
|
|
||||||
m_camera.getCameraPosition(pos);
|
|
||||||
cameraPos[0] = pos[0];
|
|
||||||
cameraPos[1] = pos[1];
|
|
||||||
cameraPos[2] = pos[2];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::getCameraPosition(double cameraPos[4])
|
|
||||||
{
|
|
||||||
float pos[3];
|
|
||||||
m_camera.getCameraPosition(pos);
|
|
||||||
cameraPos[0] = pos[0];
|
|
||||||
cameraPos[1] = pos[1];
|
|
||||||
cameraPos[2] = pos[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::setCameraTargetPosition(float cameraPos[4])
|
|
||||||
{
|
|
||||||
m_camera.setCameraTargetPosition(cameraPos[0],cameraPos[1],cameraPos[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::getCameraTargetPosition(float cameraPos[4]) const
|
|
||||||
{
|
|
||||||
m_camera.getCameraTargetPosition(cameraPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::getCameraTargetPosition(double cameraPos[4]) const
|
|
||||||
{
|
|
||||||
cameraPos[0] = 1;
|
|
||||||
cameraPos[1] = 1;
|
|
||||||
cameraPos[2] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimpleOpenGL2Renderer::writeSingleInstanceColorToCPU(float* color, int srcIndex)
|
void SimpleOpenGL2Renderer::writeSingleInstanceColorToCPU(float* color, int srcIndex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,23 +17,12 @@ struct SimpleOpenGL2Renderer : public CommonRenderInterface
|
|||||||
|
|
||||||
virtual void updateCamera(int upAxis);
|
virtual void updateCamera(int upAxis);
|
||||||
|
|
||||||
|
virtual const CommonCameraInterface* getActiveCamera() const;
|
||||||
|
virtual CommonCameraInterface* getActiveCamera();
|
||||||
|
virtual void setActiveCamera(CommonCameraInterface* cam);
|
||||||
|
|
||||||
virtual void removeAllInstances();
|
virtual void removeAllInstances();
|
||||||
|
|
||||||
virtual void setCameraDistance(float dist);
|
|
||||||
|
|
||||||
virtual void setCameraPitch(float pitch);
|
|
||||||
|
|
||||||
virtual void setCameraTargetPosition(float x, float y, float z);
|
|
||||||
|
|
||||||
virtual void getCameraPosition(float cameraPos[4]);
|
|
||||||
|
|
||||||
virtual void getCameraPosition(double cameraPos[4]);
|
|
||||||
|
|
||||||
virtual void setCameraTargetPosition(float cameraPos[4]);
|
|
||||||
|
|
||||||
virtual void getCameraTargetPosition(float cameraPos[4]) const;
|
|
||||||
|
|
||||||
virtual void getCameraTargetPosition(double cameraPos[4]) const;
|
|
||||||
|
|
||||||
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex);
|
||||||
virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex);
|
virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex);
|
||||||
|
|||||||
@@ -66,10 +66,24 @@ static void SimpleKeyboardCallback(int key, int state)
|
|||||||
gApp->m_window->setRequestExit();
|
gApp->m_window->setRequestExit();
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
b3DefaultKeyboardCallback(key,state);
|
//gApp->defaultKeyboardCallback(key,state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleMouseButtonCallback( int button, int state, float x, float y)
|
||||||
|
{
|
||||||
|
gApp->defaultMouseButtonCallback(button,state,x,y);
|
||||||
|
}
|
||||||
|
void SimpleMouseMoveCallback( float x, float y)
|
||||||
|
{
|
||||||
|
gApp->defaultMouseMoveCallback(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleWheelCallback( float deltax, float deltay)
|
||||||
|
{
|
||||||
|
gApp->defaultWheelCallback(deltax,deltay);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -152,10 +166,10 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height)
|
|||||||
|
|
||||||
m_instancingRenderer->InitShaders();
|
m_instancingRenderer->InitShaders();
|
||||||
|
|
||||||
m_window->setMouseMoveCallback(b3DefaultMouseMoveCallback);
|
m_window->setMouseMoveCallback(SimpleMouseMoveCallback);
|
||||||
m_window->setMouseButtonCallback(b3DefaultMouseButtonCallback);
|
m_window->setMouseButtonCallback(SimpleMouseButtonCallback);
|
||||||
m_window->setKeyboardCallback(SimpleKeyboardCallback);
|
m_window->setKeyboardCallback(SimpleKeyboardCallback);
|
||||||
m_window->setWheelCallback(b3DefaultWheelCallback);
|
m_window->setWheelCallback(SimpleWheelCallback);
|
||||||
m_window->setResizeCallback(SimpleResizeCallback);
|
m_window->setResizeCallback(SimpleResizeCallback);
|
||||||
|
|
||||||
TwGenerateDefaultFonts();
|
TwGenerateDefaultFonts();
|
||||||
@@ -200,12 +214,14 @@ void SimpleOpenGL3App::drawText3D( const char* txt, float worldPosX, float world
|
|||||||
|
|
||||||
float viewMat[16];
|
float viewMat[16];
|
||||||
float projMat[16];
|
float projMat[16];
|
||||||
m_instancingRenderer->getCameraViewMatrix(viewMat);
|
CommonCameraInterface* cam = m_instancingRenderer->getActiveCamera();
|
||||||
m_instancingRenderer->getCameraProjectionMatrix(projMat);
|
|
||||||
|
cam->getCameraViewMatrix(viewMat);
|
||||||
|
cam->getCameraProjectionMatrix(projMat);
|
||||||
|
|
||||||
|
|
||||||
float camPos[4];
|
float camPos[4];
|
||||||
this->m_instancingRenderer->getCameraPosition(camPos);
|
cam->getCameraPosition(camPos);
|
||||||
b3Vector3 cp= b3MakeVector3(camPos[0],camPos[2],camPos[1]);
|
b3Vector3 cp= b3MakeVector3(camPos[0],camPos[2],camPos[1]);
|
||||||
b3Vector3 p = b3MakeVector3(worldPosX,worldPosY,worldPosZ);
|
b3Vector3 p = b3MakeVector3(worldPosX,worldPosY,worldPosZ);
|
||||||
//float dist = (cp-p).length();
|
//float dist = (cp-p).length();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "../OpenGLWindow/GLInstancingRenderer.h"
|
#include "../OpenGLWindow/GLInstancingRenderer.h"
|
||||||
#include "../OpenGLWindow/GLPrimitiveRenderer.h"
|
#include "../OpenGLWindow/GLPrimitiveRenderer.h"
|
||||||
#include "../OpenGLWindow/b3gWindowInterface.h"
|
#include "../CommonInterfaces/CommonWindowInterface.h"
|
||||||
|
|
||||||
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
|
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
struct InternalData2;
|
struct InternalData2;
|
||||||
|
|
||||||
#include "b3gWindowInterface.h"
|
#include "../CommonInterfaces/CommonWindowInterface.h"
|
||||||
|
|
||||||
class Win32Window : public b3gWindowInterface
|
class Win32Window : public b3gWindowInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
#ifndef B3G_WINDOW_INTERFACE_H
|
|
||||||
#define B3G_WINDOW_INTERFACE_H
|
|
||||||
|
|
||||||
|
|
||||||
typedef void (*b3WheelCallback)(float deltax, float deltay);
|
|
||||||
typedef void (*b3ResizeCallback)( float width, float height);
|
|
||||||
typedef void (*b3MouseMoveCallback)( float x, float y);
|
|
||||||
typedef void (*b3MouseButtonCallback)(int button, int state, float x, float y);
|
|
||||||
typedef void (*b3KeyboardCallback)(int keycode, int state);
|
|
||||||
typedef void (*b3RenderCallback) ();
|
|
||||||
|
|
||||||
enum {
|
|
||||||
B3G_ESCAPE = 27,
|
|
||||||
B3G_F1 = 0xff00,
|
|
||||||
B3G_F2,
|
|
||||||
B3G_F3,
|
|
||||||
B3G_F4,
|
|
||||||
B3G_F5,
|
|
||||||
B3G_F6,
|
|
||||||
B3G_F7,
|
|
||||||
B3G_F8,
|
|
||||||
B3G_F9,
|
|
||||||
B3G_F10,
|
|
||||||
B3G_F11,
|
|
||||||
B3G_F12,
|
|
||||||
B3G_F13,
|
|
||||||
B3G_F14,
|
|
||||||
B3G_F15,
|
|
||||||
B3G_LEFT_ARROW,
|
|
||||||
B3G_RIGHT_ARROW,
|
|
||||||
B3G_UP_ARROW,
|
|
||||||
B3G_DOWN_ARROW,
|
|
||||||
B3G_PAGE_UP,
|
|
||||||
B3G_PAGE_DOWN,
|
|
||||||
B3G_END,
|
|
||||||
B3G_HOME,
|
|
||||||
B3G_INSERT,
|
|
||||||
B3G_DELETE,
|
|
||||||
B3G_BACKSPACE,
|
|
||||||
B3G_SHIFT,
|
|
||||||
B3G_CONTROL,
|
|
||||||
B3G_ALT,
|
|
||||||
B3G_RETURN
|
|
||||||
};
|
|
||||||
|
|
||||||
struct b3gWindowConstructionInfo
|
|
||||||
{
|
|
||||||
int m_width;
|
|
||||||
int m_height;
|
|
||||||
bool m_fullscreen;
|
|
||||||
int m_colorBitsPerPixel;
|
|
||||||
void* m_windowHandle;
|
|
||||||
const char* m_title;
|
|
||||||
int m_openglVersion;
|
|
||||||
|
|
||||||
|
|
||||||
b3gWindowConstructionInfo(int width=1024, int height=768)
|
|
||||||
:m_width(width),
|
|
||||||
m_height(height),
|
|
||||||
m_fullscreen(false),
|
|
||||||
m_colorBitsPerPixel(32),
|
|
||||||
m_windowHandle(0),
|
|
||||||
m_title("title"),
|
|
||||||
m_openglVersion(3)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class b3gWindowInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual ~b3gWindowInterface()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void createDefaultWindow(int width, int height, const char* title)
|
|
||||||
{
|
|
||||||
b3gWindowConstructionInfo ci(width,height);
|
|
||||||
ci.m_title = title;
|
|
||||||
createWindow(ci);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void createWindow(const b3gWindowConstructionInfo& ci)=0;
|
|
||||||
|
|
||||||
virtual void closeWindow()=0;
|
|
||||||
|
|
||||||
virtual void runMainLoop()=0;
|
|
||||||
virtual float getTimeInSeconds()=0;
|
|
||||||
|
|
||||||
virtual bool requestedExit() const = 0;
|
|
||||||
virtual void setRequestExit() = 0;
|
|
||||||
|
|
||||||
virtual void startRendering()=0;
|
|
||||||
|
|
||||||
virtual void endRendering()=0;
|
|
||||||
|
|
||||||
virtual bool isModifiedKeyPressed(int key) = 0;
|
|
||||||
|
|
||||||
virtual void setMouseMoveCallback(b3MouseMoveCallback mouseCallback)=0;
|
|
||||||
virtual b3MouseMoveCallback getMouseMoveCallback()=0;
|
|
||||||
|
|
||||||
virtual void setMouseButtonCallback(b3MouseButtonCallback mouseCallback)=0;
|
|
||||||
virtual b3MouseButtonCallback getMouseButtonCallback()=0;
|
|
||||||
|
|
||||||
virtual void setResizeCallback(b3ResizeCallback resizeCallback)=0;
|
|
||||||
virtual b3ResizeCallback getResizeCallback()=0;
|
|
||||||
|
|
||||||
virtual void setWheelCallback(b3WheelCallback wheelCallback)=0;
|
|
||||||
virtual b3WheelCallback getWheelCallback()=0;
|
|
||||||
|
|
||||||
virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback)=0;
|
|
||||||
virtual b3KeyboardCallback getKeyboardCallback()=0;
|
|
||||||
|
|
||||||
virtual void setRenderCallback( b3RenderCallback renderCallback) = 0;
|
|
||||||
|
|
||||||
virtual void setWindowTitle(const char* title)=0;
|
|
||||||
|
|
||||||
virtual float getRetinaScale() const =0;
|
|
||||||
|
|
||||||
virtual int fileOpenDialog(char* fileName, int maxFileNameLength) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //B3G_WINDOW_INTERFACE_H
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef COORDINATE_SYSTEM_DEMO_H
|
#ifndef COORDINATE_SYSTEM_DEMO_H
|
||||||
#define COORDINATE_SYSTEM_DEMO_H
|
#define COORDINATE_SYSTEM_DEMO_H
|
||||||
|
|
||||||
struct ExampleInterface* CoordinateSystemCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
class ExampleInterface* CoordinateSystemCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||||
|
|
||||||
|
|
||||||
#endif //COORDINATE_SYSTEM_DEMO_H
|
#endif //COORDINATE_SYSTEM_DEMO_H
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ void RaytracerPhysicsSetup::syncPhysicsToGraphics(GraphicsPhysicsBridge& gfxBrid
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExampleInterface* RayTracerCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
ExampleInterface* RayTracerCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||||
{
|
{
|
||||||
return new RaytracerPhysicsSetup(helper->getAppInterface());
|
return new RaytracerPhysicsSetup(helper->getAppInterface());
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef RAYTRACER_SETUP_H
|
#ifndef RAYTRACER_SETUP_H
|
||||||
#define RAYTRACER_SETUP_H
|
#define RAYTRACER_SETUP_H
|
||||||
|
|
||||||
struct ExampleInterface* RayTracerCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
class ExampleInterface* RayTracerCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||||
|
|
||||||
#endif //RAYTRACER_SETUP_H
|
#endif //RAYTRACER_SETUP_H
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ExampleInterface* RenderInstancingCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
class ExampleInterface* RenderInstancingCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||||
{
|
{
|
||||||
return new RenderInstancingDemo(helper->getAppInterface());
|
return new RenderInstancingDemo(helper->getAppInterface());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef RENDER_INSTANCING_DEMO_H
|
#ifndef RENDER_INSTANCING_DEMO_H
|
||||||
#define RENDER_INSTANCING_DEMO_H
|
#define RENDER_INSTANCING_DEMO_H
|
||||||
|
|
||||||
struct ExampleInterface* RenderInstancingCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
class ExampleInterface* RenderInstancingCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||||
|
|
||||||
#endif //RENDER_INSTANCING_DEMO_H
|
#endif //RENDER_INSTANCING_DEMO_H
|
||||||
|
|||||||
Reference in New Issue
Block a user