add initial examples, replacing the 'Demos/Demos3'. Will make it work cross-platform, OpenGL3/OpenGL2 and add more examples to it.
This commit is contained in:
148
examples/RenderingExamples/CoordinateSystemDemo.cpp
Normal file
148
examples/RenderingExamples/CoordinateSystemDemo.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
|
||||
#include "CoordinateSystemDemo.h"
|
||||
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
|
||||
#include "../CommonInterfaces/CommonRenderInterface.h"
|
||||
|
||||
#include "../CommonInterfaces/ExampleInterface.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "GUIHelperInterface.h"
|
||||
///quick demo showing the right-handed coordinate system and positive rotations around each axis
|
||||
class CoordinateSystemDemo : public ExampleInterface
|
||||
{
|
||||
CommonGraphicsApp* m_app;
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
|
||||
public:
|
||||
|
||||
CoordinateSystemDemo(CommonGraphicsApp* app)
|
||||
:m_app(app),
|
||||
m_x(0),
|
||||
m_y(0),
|
||||
m_z(0)
|
||||
{
|
||||
m_app->setUpAxis(2);
|
||||
|
||||
{
|
||||
int boxId = m_app->registerCubeShape(0.1,0.1,0.1);
|
||||
btVector3 pos(0,0,0);
|
||||
btQuaternion orn(0,0,0,1);
|
||||
btVector4 color(0.3,0.3,0.3,1);
|
||||
btVector3 scaling(1,1,1);
|
||||
m_app->m_renderer->registerGraphicsInstance(boxId,pos,orn,color,scaling);
|
||||
}
|
||||
|
||||
m_app->m_renderer->writeTransforms();
|
||||
}
|
||||
virtual ~CoordinateSystemDemo()
|
||||
{
|
||||
m_app->m_renderer->enableBlend(false);
|
||||
}
|
||||
|
||||
|
||||
virtual void initPhysics()
|
||||
{
|
||||
}
|
||||
virtual void exitPhysics()
|
||||
{
|
||||
|
||||
}
|
||||
virtual void stepSimulation(float deltaTime)
|
||||
{
|
||||
m_x+=0.01f;
|
||||
m_y+=0.01f;
|
||||
m_z+=0.01f;
|
||||
|
||||
}
|
||||
virtual void renderScene()
|
||||
{
|
||||
m_app->m_renderer->renderScene();
|
||||
m_app->drawText3D("X",1,0,0,1);
|
||||
m_app->drawText3D("Y",0,1,0,1);
|
||||
m_app->drawText3D("Z",0,0,1,1);
|
||||
}
|
||||
|
||||
virtual void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle,
|
||||
const btVector3& color, bool drawSect, btScalar stepDegrees = btScalar(10.f))
|
||||
{
|
||||
btScalar lineWidth = 3;
|
||||
const btVector3& vx = axis;
|
||||
btVector3 vy = normal.cross(axis);
|
||||
btScalar step = stepDegrees * SIMD_RADS_PER_DEG;
|
||||
int nSteps = (int)btFabs((maxAngle - minAngle) / step);
|
||||
if(!nSteps) nSteps = 1;
|
||||
btVector3 prev = center + radiusA * vx * btCos(minAngle) + radiusB * vy * btSin(minAngle);
|
||||
if(drawSect)
|
||||
{
|
||||
m_app->m_renderer->drawLine(center, prev, color,lineWidth);
|
||||
}
|
||||
for(int i = 1; i <= nSteps; i++)
|
||||
{
|
||||
btScalar angle = minAngle + (maxAngle - minAngle) * btScalar(i) / btScalar(nSteps);
|
||||
btVector3 next = center + radiusA * vx * btCos(angle) + radiusB * vy * btSin(angle);
|
||||
m_app->m_renderer->drawLine(prev, next, color,lineWidth);
|
||||
prev = next;
|
||||
}
|
||||
if(drawSect)
|
||||
{
|
||||
m_app->m_renderer->drawLine(center, prev, color,lineWidth);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void physicsDebugDraw(int debugDrawFlags)
|
||||
{
|
||||
|
||||
btVector3 xUnit(1,0,0);
|
||||
btVector3 yUnit(0,1,0);
|
||||
btVector3 zUnit(0,0,1);
|
||||
|
||||
btScalar lineWidth=3;
|
||||
|
||||
btQuaternion rotAroundX(xUnit,m_x);
|
||||
btQuaternion rotAroundY(yUnit,m_y);
|
||||
btQuaternion rotAroundZ(zUnit,m_z);
|
||||
|
||||
btScalar radius=0.5;
|
||||
btVector3 toX=radius*quatRotate(rotAroundX,yUnit);
|
||||
btVector3 toY=radius*quatRotate(rotAroundY,xUnit);
|
||||
btVector3 toZ=radius*quatRotate(rotAroundZ,xUnit);
|
||||
|
||||
m_app->m_renderer->drawLine(xUnit+toX+quatRotate(rotAroundX,btVector3(0,0.1,-0.2)),xUnit+toX,xUnit,lineWidth);
|
||||
m_app->m_renderer->drawLine(xUnit+toX+quatRotate(rotAroundX,btVector3(0,-0.2,-0.2)),xUnit+toX,xUnit,lineWidth);
|
||||
//draw the letter 'x' on the x-axis
|
||||
//m_app->m_renderer->drawLine(xUnit-0.1*zUnit+0.1*yUnit,xUnit+0.1*zUnit-0.1*yUnit,xUnit,lineWidth);
|
||||
//m_app->m_renderer->drawLine(xUnit+0.1*zUnit+0.1*yUnit,xUnit-0.1*zUnit-0.1*yUnit,xUnit,lineWidth);
|
||||
|
||||
m_app->m_renderer->drawLine(xUnit+toX+quatRotate(rotAroundX,btVector3(0,-0.2,-0.2)),xUnit+toX,xUnit,lineWidth);
|
||||
|
||||
m_app->m_renderer->drawLine(yUnit+toY+quatRotate(rotAroundY,btVector3(-0.2,0,0.2)),yUnit+toY,yUnit,lineWidth);
|
||||
m_app->m_renderer->drawLine(yUnit+toY+quatRotate(rotAroundY,btVector3(0.1,0,0.2)),yUnit+toY,yUnit,lineWidth);
|
||||
m_app->m_renderer->drawLine(zUnit+toZ+quatRotate(rotAroundZ,btVector3(0.1,-0.2,0)),zUnit+toZ,zUnit,lineWidth);
|
||||
m_app->m_renderer->drawLine(zUnit+toZ+quatRotate(rotAroundZ,btVector3(-0.2,-0.2,0)),zUnit+toZ,zUnit,lineWidth);
|
||||
|
||||
|
||||
drawArc(xUnit,xUnit,toX.normalized(),radius,radius,0.4,SIMD_2_PI,xUnit,false);
|
||||
drawArc(yUnit,yUnit,toY.normalized(),radius,radius,0.4,SIMD_2_PI,yUnit,false);
|
||||
drawArc(zUnit,zUnit,toZ.normalized(),radius,radius,0.4,SIMD_2_PI,zUnit,false);
|
||||
}
|
||||
virtual bool mouseMoveCallback(float x,float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool keyboardCallback(int key, int state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct ExampleInterface* CoordinateSystemCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||
{
|
||||
return new CoordinateSystemDemo(helper->getAppInterface());
|
||||
}
|
||||
|
||||
8
examples/RenderingExamples/CoordinateSystemDemo.h
Normal file
8
examples/RenderingExamples/CoordinateSystemDemo.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef COORDINATE_SYSTEM_DEMO_H
|
||||
#define COORDINATE_SYSTEM_DEMO_H
|
||||
|
||||
struct ExampleInterface* CoordinateSystemCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||
|
||||
|
||||
#endif //COORDINATE_SYSTEM_DEMO_H
|
||||
|
||||
384
examples/RenderingExamples/RaytracerSetup.cpp
Normal file
384
examples/RenderingExamples/RaytracerSetup.cpp
Normal file
@@ -0,0 +1,384 @@
|
||||
|
||||
#include "RaytracerSetup.h"
|
||||
|
||||
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
|
||||
#include "Bullet3Common/b3Quaternion.h"
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "../CommonInterfaces/CommonRenderInterface.h"
|
||||
|
||||
|
||||
#include "../CommonInterfaces/Common2dCanvasInterface.h"
|
||||
//#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
|
||||
//#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
|
||||
//#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
|
||||
#include "../CommonInterfaces/ExampleInterface.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "btBulletCollisionCommon.h"
|
||||
#include "GUIHelperInterface.h"
|
||||
|
||||
struct RaytracerPhysicsSetup : public ExampleInterface
|
||||
{
|
||||
|
||||
struct CommonGraphicsApp* m_app;
|
||||
struct RaytracerInternalData* m_internalData;
|
||||
|
||||
RaytracerPhysicsSetup(struct CommonGraphicsApp* app);
|
||||
|
||||
virtual ~RaytracerPhysicsSetup();
|
||||
|
||||
virtual void initPhysics();
|
||||
|
||||
virtual void exitPhysics();
|
||||
|
||||
virtual void stepSimulation(float deltaTime);
|
||||
|
||||
|
||||
virtual void physicsDebugDraw(int debugFlags);
|
||||
|
||||
virtual void syncPhysicsToGraphics(struct GraphicsPhysicsBridge& gfxBridge);
|
||||
|
||||
///worldRaytest performs a ray versus all objects in a collision world, returning true is a hit is found (filling in worldNormal and worldHitPoint)
|
||||
bool worldRaytest(const btVector3& rayFrom,const btVector3& rayTo,btVector3& worldNormal,btVector3& worldHitPoint);
|
||||
|
||||
///singleObjectRaytest performs a ray versus one collision shape, returning true is a hit is found (filling in worldNormal and worldHitPoint)
|
||||
bool singleObjectRaytest(const btVector3& rayFrom,const btVector3& rayTo,btVector3& worldNormal,btVector3& worldHitPoint);
|
||||
|
||||
///lowlevelRaytest performs a ray versus convex shape, returning true is a hit is found (filling in worldNormal and worldHitPoint)
|
||||
bool lowlevelRaytest(const btVector3& rayFrom,const btVector3& rayTo,btVector3& worldNormal,btVector3& worldHitPoint);
|
||||
|
||||
virtual bool RaytracerPhysicsSetup::mouseMoveCallback(float x,float y);
|
||||
|
||||
virtual bool RaytracerPhysicsSetup::mouseButtonCallback(int button, int state, float x, float y);
|
||||
|
||||
virtual bool RaytracerPhysicsSetup::keyboardCallback(int key, int state);
|
||||
|
||||
virtual void renderScene()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct RaytracerInternalData
|
||||
{
|
||||
int m_canvasIndex;
|
||||
struct Common2dCanvasInterface* m_canvas;
|
||||
|
||||
int m_width;
|
||||
int m_height;
|
||||
|
||||
btAlignedObjectArray<btConvexShape*> m_shapePtr;
|
||||
btAlignedObjectArray<btTransform> m_transforms;
|
||||
btVoronoiSimplexSolver m_simplexSolver;
|
||||
btScalar m_pitch;
|
||||
btScalar m_roll;
|
||||
btScalar m_yaw;
|
||||
|
||||
RaytracerInternalData()
|
||||
:m_canvasIndex(-1),
|
||||
m_canvas(0),
|
||||
m_roll(0),
|
||||
m_pitch(0),
|
||||
m_yaw(0),
|
||||
#ifdef _DEBUG
|
||||
m_width(64),
|
||||
m_height(64)
|
||||
#else
|
||||
m_width(128),
|
||||
m_height(128)
|
||||
#endif
|
||||
{
|
||||
btConeShape* cone = new btConeShape(1,1);
|
||||
btSphereShape* sphere = new btSphereShape(1);
|
||||
btBoxShape* box = new btBoxShape (btVector3(1,1,1));
|
||||
m_shapePtr.push_back(cone);
|
||||
m_shapePtr.push_back(sphere);
|
||||
m_shapePtr.push_back(box);
|
||||
|
||||
updateTransforms();
|
||||
}
|
||||
void updateTransforms()
|
||||
{
|
||||
int numObjects = m_shapePtr.size();
|
||||
m_transforms.resize(numObjects);
|
||||
for (int i=0;i<numObjects;i++)
|
||||
{
|
||||
m_transforms[i].setIdentity();
|
||||
btVector3 pos(0.f,0.f,-(2.5* numObjects * 0.5)+i*2.5f);
|
||||
m_transforms[i].setIdentity();
|
||||
m_transforms[i].setOrigin( pos );
|
||||
btQuaternion orn;
|
||||
if (i < 2)
|
||||
{
|
||||
orn.setEuler(m_yaw,m_pitch,m_roll);
|
||||
m_transforms[i].setRotation(orn);
|
||||
}
|
||||
}
|
||||
m_pitch += 0.005f;
|
||||
m_yaw += 0.01f;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
RaytracerPhysicsSetup::RaytracerPhysicsSetup(struct CommonGraphicsApp* app)
|
||||
{
|
||||
m_app = app;
|
||||
m_internalData = new RaytracerInternalData;
|
||||
}
|
||||
|
||||
RaytracerPhysicsSetup::~RaytracerPhysicsSetup()
|
||||
{
|
||||
delete m_internalData;
|
||||
}
|
||||
|
||||
void RaytracerPhysicsSetup::initPhysics()
|
||||
{
|
||||
//request a visual bitma/texture we can render to
|
||||
|
||||
|
||||
|
||||
m_internalData->m_canvas = m_app->m_2dCanvasInterface;
|
||||
|
||||
|
||||
if (m_internalData->m_canvas)
|
||||
{
|
||||
|
||||
m_internalData->m_canvasIndex = m_internalData->m_canvas->createCanvas("raytracer",m_internalData->m_width,m_internalData->m_height);
|
||||
for (int i=0;i<m_internalData->m_width;i++)
|
||||
{
|
||||
for (int j=0;j<m_internalData->m_height;j++)
|
||||
{
|
||||
unsigned char red=255;
|
||||
unsigned char green=255;
|
||||
unsigned char blue=255;
|
||||
unsigned char alpha=255;
|
||||
m_internalData->m_canvas->setPixel(m_internalData->m_canvasIndex,i,j,red,green,blue,alpha);
|
||||
}
|
||||
}
|
||||
m_internalData->m_canvas->refreshImageData(m_internalData->m_canvasIndex);
|
||||
|
||||
//int bitmapId = gfxBridge.createRenderBitmap(width,height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
///worldRaytest performs a ray versus all objects in a collision world, returning true is a hit is found (filling in worldNormal and worldHitPoint)
|
||||
bool RaytracerPhysicsSetup::worldRaytest(const btVector3& rayFrom,const btVector3& rayTo,btVector3& worldNormal,btVector3& worldHitPoint)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///singleObjectRaytest performs a ray versus one collision shape, returning true is a hit is found (filling in worldNormal and worldHitPoint)
|
||||
bool RaytracerPhysicsSetup::singleObjectRaytest(const btVector3& rayFrom,const btVector3& rayTo,btVector3& worldNormal,btVector3& worldHitPoint)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///lowlevelRaytest performs a ray versus convex shape, returning true is a hit is found (filling in worldNormal and worldHitPoint)
|
||||
bool RaytracerPhysicsSetup::lowlevelRaytest(const btVector3& rayFrom,const btVector3& rayTo,btVector3& worldNormal,btVector3& worldHitPoint)
|
||||
{
|
||||
btScalar closestHitResults = 1.f;
|
||||
|
||||
bool hasHit = false;
|
||||
btConvexCast::CastResult rayResult;
|
||||
btSphereShape pointShape(0.0f);
|
||||
btTransform rayFromTrans;
|
||||
btTransform rayToTrans;
|
||||
|
||||
rayFromTrans.setIdentity();
|
||||
rayFromTrans.setOrigin(rayFrom);
|
||||
rayToTrans.setIdentity();
|
||||
rayToTrans.setOrigin(rayTo);
|
||||
|
||||
int numObjects = m_internalData->m_shapePtr.size();
|
||||
|
||||
for (int s=0;s<numObjects;s++)
|
||||
{
|
||||
|
||||
//do some culling, ray versus aabb
|
||||
btVector3 aabbMin,aabbMax;
|
||||
m_internalData->m_shapePtr[s]->getAabb( m_internalData->m_transforms[s],aabbMin,aabbMax);
|
||||
btScalar hitLambda = 1.f;
|
||||
btVector3 hitNormal;
|
||||
btCollisionObject tmpObj;
|
||||
tmpObj.setWorldTransform( m_internalData->m_transforms[s]);
|
||||
|
||||
|
||||
if (btRayAabb(rayFrom,rayTo,aabbMin,aabbMax,hitLambda,hitNormal))
|
||||
{
|
||||
//reset previous result
|
||||
|
||||
//choose the continuous collision detection method
|
||||
btSubsimplexConvexCast convexCaster(&pointShape, m_internalData->m_shapePtr[s],&m_internalData->m_simplexSolver);
|
||||
//btGjkConvexCast convexCaster(&pointShape,shapePtr[s],&simplexSolver);
|
||||
//btContinuousConvexCollision convexCaster(&pointShape,shapePtr[s],&simplexSolver,0);
|
||||
|
||||
if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans, m_internalData->m_transforms[s], m_internalData->m_transforms[s],rayResult))
|
||||
{
|
||||
if (rayResult.m_fraction < closestHitResults)
|
||||
{
|
||||
closestHitResults = rayResult.m_fraction;
|
||||
|
||||
worldNormal = m_internalData->m_transforms[s].getBasis() *rayResult.m_normal;
|
||||
worldNormal.normalize();
|
||||
hasHit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return hasHit;
|
||||
|
||||
}
|
||||
|
||||
void RaytracerPhysicsSetup::exitPhysics()
|
||||
{
|
||||
|
||||
if (m_internalData->m_canvas && m_internalData->m_canvasIndex>=0)
|
||||
{
|
||||
m_internalData->m_canvas->destroyCanvas(m_internalData->m_canvasIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void RaytracerPhysicsSetup::stepSimulation(float deltaTime)
|
||||
{
|
||||
|
||||
m_internalData->updateTransforms();
|
||||
|
||||
|
||||
float top = 1.f;
|
||||
float bottom = -1.f;
|
||||
float nearPlane = 1.f;
|
||||
|
||||
float tanFov = (top-bottom)*0.5f / nearPlane;
|
||||
|
||||
float fov = 2.0 * atanf (tanFov);
|
||||
|
||||
btVector3 cameraPosition(5,0,0);
|
||||
btVector3 cameraTargetPosition(0,0,0);
|
||||
|
||||
btVector3 rayFrom = cameraPosition;
|
||||
btVector3 rayForward = cameraTargetPosition-cameraPosition;
|
||||
rayForward.normalize();
|
||||
float farPlane = 600.f;
|
||||
rayForward*= farPlane;
|
||||
|
||||
btVector3 rightOffset;
|
||||
btVector3 vertical(0.f,1.f,0.f);
|
||||
btVector3 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;
|
||||
|
||||
btVector3 rayToCenter = rayFrom + rayForward;
|
||||
|
||||
btVector3 dHor = hor * 1.f/float(m_internalData->m_width);
|
||||
btVector3 dVert = vertical * 1.f/float(m_internalData->m_height);
|
||||
|
||||
|
||||
|
||||
|
||||
int mode = 0;
|
||||
int x,y;
|
||||
|
||||
for (x=0;x<m_internalData->m_width;x++)
|
||||
{
|
||||
for (int y=0;y<m_internalData->m_height;y++)
|
||||
{
|
||||
btVector4 rgba(0,0,0,0);
|
||||
btVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical;
|
||||
rayTo += x * dHor;
|
||||
rayTo -= y * dVert;
|
||||
btVector3 worldNormal(0,0,0);
|
||||
btVector3 worldPoint(0,0,0);
|
||||
|
||||
|
||||
|
||||
bool hasHit = false;
|
||||
int mode = 0;
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
hasHit = lowlevelRaytest(rayFrom,rayTo,worldNormal,worldPoint);
|
||||
break;
|
||||
case 1:
|
||||
hasHit = singleObjectRaytest(rayFrom,rayTo,worldNormal,worldPoint);
|
||||
break;
|
||||
case 2:
|
||||
hasHit = worldRaytest(rayFrom,rayTo,worldNormal,worldPoint);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (hasHit)
|
||||
{
|
||||
float lightVec0 = worldNormal.dot(btVector3(0,-1,-1));//0.4f,-1.f,-0.4f));
|
||||
float lightVec1= worldNormal.dot(btVector3(-1,0,-1));//-0.4f,-1.f,-0.4f));
|
||||
|
||||
|
||||
rgba = btVector4(lightVec0,lightVec1,0,1.f);
|
||||
rgba.setMin(btVector3(1,1,1));
|
||||
rgba.setMax(btVector3(0.2,0.2,0.2));
|
||||
rgba[3] = 1.f;
|
||||
unsigned char red = rgba[0] * 255;
|
||||
unsigned char green = rgba[1] * 255;
|
||||
unsigned char blue = rgba[2] * 255;
|
||||
unsigned char alpha=255;
|
||||
m_internalData->m_canvas->setPixel(m_internalData->m_canvasIndex,x,y,red,green,blue,alpha);
|
||||
|
||||
} else
|
||||
{
|
||||
// btVector4 rgba = raytracePicture->getPixel(x,y);
|
||||
}
|
||||
if (!rgba.length2())
|
||||
{
|
||||
m_internalData->m_canvas->setPixel(m_internalData->m_canvasIndex,x,y,255,0,0,255);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_internalData->m_canvas->refreshImageData(m_internalData->m_canvasIndex);
|
||||
}
|
||||
|
||||
|
||||
void RaytracerPhysicsSetup::physicsDebugDraw(int debugDrawFlags)
|
||||
{
|
||||
}
|
||||
|
||||
bool RaytracerPhysicsSetup::mouseMoveCallback(float x,float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RaytracerPhysicsSetup::mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RaytracerPhysicsSetup::keyboardCallback(int key, int state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void RaytracerPhysicsSetup::syncPhysicsToGraphics(GraphicsPhysicsBridge& gfxBridge)
|
||||
{
|
||||
}
|
||||
|
||||
struct ExampleInterface* RayTracerCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||
{
|
||||
return new RaytracerPhysicsSetup(helper->getAppInterface());
|
||||
}
|
||||
6
examples/RenderingExamples/RaytracerSetup.h
Normal file
6
examples/RenderingExamples/RaytracerSetup.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef RAYTRACER_SETUP_H
|
||||
#define RAYTRACER_SETUP_H
|
||||
|
||||
struct ExampleInterface* RayTracerCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||
|
||||
#endif //RAYTRACER_SETUP_H
|
||||
138
examples/RenderingExamples/RenderInstancingDemo.cpp
Normal file
138
examples/RenderingExamples/RenderInstancingDemo.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
#ifndef RENDER_INSTANCING_DEMO_H
|
||||
#define RENDER_INSTANCING_DEMO_H
|
||||
|
||||
|
||||
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
|
||||
#include "Bullet3Common/b3Quaternion.h"
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "../CommonInterfaces/CommonRenderInterface.h"
|
||||
#include "../CommonInterfaces/ExampleInterface.h"
|
||||
#include "GUIHelperInterface.h"
|
||||
|
||||
///quick demo showing the right-handed coordinate system and positive rotations around each axis
|
||||
class RenderInstancingDemo : public ExampleInterface
|
||||
{
|
||||
CommonGraphicsApp* m_app;
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
b3AlignedObjectArray<int> m_movingInstances;
|
||||
enum
|
||||
{
|
||||
numCubesX = 20,
|
||||
numCubesY = 20
|
||||
};
|
||||
public:
|
||||
|
||||
RenderInstancingDemo(CommonGraphicsApp* app)
|
||||
:m_app(app),
|
||||
m_x(0),
|
||||
m_y(0),
|
||||
m_z(0)
|
||||
{
|
||||
m_app->setUpAxis(2);
|
||||
|
||||
{
|
||||
b3Vector3 extents=b3MakeVector3(100,100,100);
|
||||
extents[m_app->getUpAxis()]=1;
|
||||
|
||||
int xres = 20;
|
||||
int yres = 20;
|
||||
|
||||
b3Vector4 color0=b3MakeVector4(0.1, 0.1, 0.1,1);
|
||||
b3Vector4 color1=b3MakeVector4(0.6, 0.6, 0.6,1);
|
||||
m_app->registerGrid(xres, yres, color0, color1);
|
||||
}
|
||||
|
||||
{
|
||||
int boxId = m_app->registerCubeShape(0.1,0.1,0.1);
|
||||
|
||||
|
||||
|
||||
for (int i=-numCubesX/2;i<numCubesX/2;i++)
|
||||
{
|
||||
for (int j = -numCubesY/2;j<numCubesY/2;j++)
|
||||
{
|
||||
b3Vector3 pos=b3MakeVector3(i,j,j);
|
||||
pos[app->getUpAxis()] = 1;
|
||||
b3Quaternion orn(0,0,0,1);
|
||||
b3Vector4 color=b3MakeVector4(0.3,0.3,0.3,1);
|
||||
b3Vector3 scaling=b3MakeVector3(1,1,1);
|
||||
int instanceId = m_app->m_renderer->registerGraphicsInstance(boxId,pos,orn,color,scaling);
|
||||
m_movingInstances.push_back(instanceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_app->m_renderer->writeTransforms();
|
||||
}
|
||||
virtual ~RenderInstancingDemo()
|
||||
{
|
||||
m_app->m_renderer->enableBlend(false);
|
||||
}
|
||||
|
||||
|
||||
virtual void physicsDebugDraw(int debugDrawMode)
|
||||
{
|
||||
|
||||
}
|
||||
virtual void initPhysics()
|
||||
{
|
||||
}
|
||||
virtual void exitPhysics()
|
||||
{
|
||||
|
||||
}
|
||||
virtual void stepSimulation(float deltaTime)
|
||||
{
|
||||
m_x+=0.01f;
|
||||
m_y+=0.01f;
|
||||
m_z+=0.01f;
|
||||
int index=0;
|
||||
for (int i=-numCubesX/2;i<numCubesX/2;i++)
|
||||
{
|
||||
for (int j = -numCubesY/2;j<numCubesY/2;j++)
|
||||
{
|
||||
b3Vector3 pos=b3MakeVector3(i,j,j);
|
||||
pos[m_app->getUpAxis()] = 1+1*b3Sin(m_x+i-j);
|
||||
float orn[4]={0,0,0,1};
|
||||
m_app->m_renderer->writeSingleInstanceTransformToCPU(pos,orn,m_movingInstances[index++]);
|
||||
}
|
||||
}
|
||||
m_app->m_renderer->writeTransforms();
|
||||
|
||||
}
|
||||
virtual void renderScene()
|
||||
{
|
||||
m_app->m_renderer->renderScene();
|
||||
}
|
||||
|
||||
|
||||
virtual void physicsDebugDraw()
|
||||
{
|
||||
|
||||
}
|
||||
virtual bool mouseMoveCallback(float x,float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool keyboardCallback(int key, int state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct ExampleInterface* RenderInstancingCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option)
|
||||
{
|
||||
return new RenderInstancingDemo(helper->getAppInterface());
|
||||
}
|
||||
|
||||
#endif //RENDER_INSTANCING_DEMO_H
|
||||
|
||||
|
||||
6
examples/RenderingExamples/RenderInstancingDemo.h
Normal file
6
examples/RenderingExamples/RenderInstancingDemo.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef RENDER_INSTANCING_DEMO_H
|
||||
#define RENDER_INSTANCING_DEMO_H
|
||||
|
||||
struct ExampleInterface* RenderInstancingCreateFunc(struct PhysicsInterface* pint, struct GUIHelperInterface* helper, int option);
|
||||
|
||||
#endif //RENDER_INSTANCING_DEMO_H
|
||||
Reference in New Issue
Block a user