Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "../CommonInterfaces/CommonRenderInterface.h"
|
||||
|
||||
|
||||
#include "../CommonInterfaces/Common2dCanvasInterface.h"
|
||||
//#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
|
||||
@@ -19,7 +18,6 @@
|
||||
|
||||
struct RaytracerPhysicsSetup : public CommonExampleInterface
|
||||
{
|
||||
|
||||
struct CommonGraphicsApp* m_app;
|
||||
struct RaytracerInternalData* m_internalData;
|
||||
|
||||
@@ -33,27 +31,26 @@ struct RaytracerPhysicsSetup : public CommonExampleInterface
|
||||
|
||||
virtual void stepSimulation(float deltaTime);
|
||||
|
||||
|
||||
virtual void physicsDebugDraw(int debugFlags);
|
||||
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);
|
||||
///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);
|
||||
|
||||
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);
|
||||
bool lowlevelRaytest(const btVector3& rayFrom, const btVector3& rayTo, btVector3& worldNormal, btVector3& worldHitPoint);
|
||||
|
||||
virtual bool mouseMoveCallback(float x,float y);
|
||||
virtual bool mouseMoveCallback(float x, float y);
|
||||
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y);
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y);
|
||||
|
||||
virtual bool keyboardCallback(int key, int state);
|
||||
virtual bool keyboardCallback(int key, int state);
|
||||
|
||||
virtual void renderScene()
|
||||
virtual void renderScene()
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -68,55 +65,54 @@ struct RaytracerInternalData
|
||||
|
||||
btAlignedObjectArray<btConvexShape*> m_shapePtr;
|
||||
btAlignedObjectArray<btTransform> m_transforms;
|
||||
btVoronoiSimplexSolver m_simplexSolver;
|
||||
btVoronoiSimplexSolver m_simplexSolver;
|
||||
btScalar m_pitch;
|
||||
btScalar m_roll;
|
||||
btScalar m_yaw;
|
||||
|
||||
|
||||
RaytracerInternalData()
|
||||
:m_canvasIndex(-1),
|
||||
m_canvas(0),
|
||||
: m_canvasIndex(-1),
|
||||
m_canvas(0),
|
||||
#ifdef _DEBUG
|
||||
m_width(64),
|
||||
m_height(64),
|
||||
m_width(64),
|
||||
m_height(64),
|
||||
#else
|
||||
m_width(128),
|
||||
m_height(128),
|
||||
m_width(128),
|
||||
m_height(128),
|
||||
#endif
|
||||
m_pitch(0),
|
||||
m_roll(0),
|
||||
m_yaw(0)
|
||||
m_pitch(0),
|
||||
m_roll(0),
|
||||
m_yaw(0)
|
||||
{
|
||||
btConeShape* cone = new btConeShape(1,1);
|
||||
btConeShape* cone = new btConeShape(1, 1);
|
||||
btSphereShape* sphere = new btSphereShape(1);
|
||||
btBoxShape* box = new btBoxShape (btVector3(1,1,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++)
|
||||
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);
|
||||
btVector3 pos(0.f, 0.f, -(2.5 * numObjects * 0.5) + i * 2.5f);
|
||||
m_transforms[i].setIdentity();
|
||||
m_transforms[i].setOrigin( pos );
|
||||
m_transforms[i].setOrigin(pos);
|
||||
btQuaternion orn;
|
||||
if (i < 2)
|
||||
{
|
||||
orn.setEuler(m_yaw,m_pitch,m_roll);
|
||||
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)
|
||||
@@ -133,54 +129,43 @@ RaytracerPhysicsSetup::~RaytracerPhysicsSetup()
|
||||
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, 15,55);
|
||||
for (int i=0;i<m_internalData->m_width;i++)
|
||||
m_internalData->m_canvasIndex = m_internalData->m_canvas->createCanvas("raytracer", m_internalData->m_width, m_internalData->m_height, 15, 55);
|
||||
for (int i = 0; i < m_internalData->m_width; i++)
|
||||
{
|
||||
for (int j=0;j<m_internalData->m_height;j++)
|
||||
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);
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
bool RaytracerPhysicsSetup::lowlevelRaytest(const btVector3& rayFrom, const btVector3& rayTo, btVector3& worldNormal, btVector3& worldHitPoint)
|
||||
{
|
||||
btScalar closestHitResults = 1.f;
|
||||
|
||||
@@ -197,50 +182,45 @@ bool RaytracerPhysicsSetup::lowlevelRaytest(const btVector3& rayFrom,const btVec
|
||||
|
||||
int numObjects = m_internalData->m_shapePtr.size();
|
||||
|
||||
for (int s=0;s<numObjects;s++)
|
||||
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);
|
||||
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]);
|
||||
btCollisionObject tmpObj;
|
||||
tmpObj.setWorldTransform(m_internalData->m_transforms[s]);
|
||||
|
||||
|
||||
if (btRayAabb(rayFrom,rayTo,aabbMin,aabbMax,hitLambda,hitNormal))
|
||||
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);
|
||||
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 (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 = 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)
|
||||
if (m_internalData->m_canvas && m_internalData->m_canvasIndex >= 0)
|
||||
{
|
||||
m_internalData->m_canvas->destroyCanvas(m_internalData->m_canvasIndex);
|
||||
}
|
||||
@@ -248,147 +228,134 @@ void RaytracerPhysicsSetup::exitPhysics()
|
||||
|
||||
void RaytracerPhysicsSetup::stepSimulation(float deltaTime)
|
||||
{
|
||||
|
||||
m_internalData->updateTransforms();
|
||||
|
||||
|
||||
float top = 1.f;
|
||||
float top = 1.f;
|
||||
float bottom = -1.f;
|
||||
float nearPlane = 1.f;
|
||||
|
||||
float tanFov = (top-bottom)*0.5f / nearPlane;
|
||||
float tanFov = (top - bottom) * 0.5f / nearPlane;
|
||||
|
||||
float fov = 2.0 * atanf (tanFov);
|
||||
float fov = 2.0 * atanf(tanFov);
|
||||
|
||||
|
||||
btVector3 cameraPosition(5,0,0);
|
||||
btVector3 cameraTargetPosition(0,0,0);
|
||||
btVector3 cameraPosition(5, 0, 0);
|
||||
btVector3 cameraTargetPosition(0, 0, 0);
|
||||
|
||||
|
||||
if (m_app->m_renderer && m_app->m_renderer->getActiveCamera())
|
||||
{
|
||||
m_app->m_renderer->getActiveCamera()->getCameraPosition(cameraPosition);
|
||||
m_app->m_renderer->getActiveCamera()->getCameraTargetPosition(cameraTargetPosition);
|
||||
}
|
||||
|
||||
btVector3 rayFrom = cameraPosition;
|
||||
btVector3 rayForward = cameraTargetPosition-cameraPosition;
|
||||
if (m_app->m_renderer && m_app->m_renderer->getActiveCamera())
|
||||
{
|
||||
m_app->m_renderer->getActiveCamera()->getCameraPosition(cameraPosition);
|
||||
m_app->m_renderer->getActiveCamera()->getCameraTargetPosition(cameraTargetPosition);
|
||||
}
|
||||
|
||||
|
||||
rayForward.normalize();
|
||||
btVector3 rayFrom = cameraPosition;
|
||||
btVector3 rayForward = cameraTargetPosition - cameraPosition;
|
||||
|
||||
rayForward.normalize();
|
||||
float farPlane = 600.f;
|
||||
rayForward*= farPlane;
|
||||
rayForward *= farPlane;
|
||||
|
||||
btVector3 rightOffset;
|
||||
btVector3 vertical(0.f,1.f,0.f);
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
|
||||
|
||||
// int mode = 0;
|
||||
int x,y;
|
||||
|
||||
for (x=0;x<m_internalData->m_width;x++)
|
||||
for (x = 0; x < m_internalData->m_width; x++)
|
||||
{
|
||||
for (y=0;y<m_internalData->m_height;y++)
|
||||
for (y = 0; y < m_internalData->m_height; y++)
|
||||
{
|
||||
btVector4 rgba(0,0,0,0);
|
||||
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);
|
||||
|
||||
|
||||
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:
|
||||
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));
|
||||
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 = 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);
|
||||
}
|
||||
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->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)
|
||||
void RaytracerPhysicsSetup::physicsDebugDraw(int debugDrawFlags)
|
||||
{
|
||||
}
|
||||
|
||||
bool RaytracerPhysicsSetup::mouseMoveCallback(float x,float y)
|
||||
bool RaytracerPhysicsSetup::mouseMoveCallback(float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RaytracerPhysicsSetup::mouseButtonCallback(int button, int state, float x, float y)
|
||||
bool RaytracerPhysicsSetup::mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RaytracerPhysicsSetup::keyboardCallback(int key, int state)
|
||||
bool RaytracerPhysicsSetup::keyboardCallback(int key, int state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void RaytracerPhysicsSetup::syncPhysicsToGraphics(GraphicsPhysicsBridge& gfxBridge)
|
||||
{
|
||||
}
|
||||
|
||||
CommonExampleInterface* RayTracerCreateFunc(struct CommonExampleOptions& options)
|
||||
{
|
||||
return new RaytracerPhysicsSetup(options.m_guiHelper->getAppInterface());
|
||||
}
|
||||
CommonExampleInterface* RayTracerCreateFunc(struct CommonExampleOptions& options)
|
||||
{
|
||||
return new RaytracerPhysicsSetup(options.m_guiHelper->getAppInterface());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user