2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
#include "CoordinateSystemDemo.h"
|
|
|
|
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
|
|
|
|
#include "../CommonInterfaces/CommonRenderInterface.h"
|
|
|
|
|
2015-04-29 20:33:26 +00:00
|
|
|
#include "../CommonInterfaces/CommonExampleInterface.h"
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "LinearMath/btTransform.h"
|
2015-04-20 22:28:52 +00:00
|
|
|
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
2015-04-16 16:55:32 +00:00
|
|
|
///quick demo showing the right-handed coordinate system and positive rotations around each axis
|
2015-04-29 20:33:26 +00:00
|
|
|
class CoordinateSystemDemo : public CommonExampleInterface
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
CommonGraphicsApp* m_app;
|
|
|
|
float m_x;
|
|
|
|
float m_y;
|
|
|
|
float m_z;
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
public:
|
2018-09-23 21:17:31 +00:00
|
|
|
CoordinateSystemDemo(CommonGraphicsApp* app)
|
|
|
|
: m_app(app),
|
|
|
|
m_x(0),
|
|
|
|
m_y(0),
|
|
|
|
m_z(0)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
m_app->setUpAxis(2);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
m_app->m_renderer->renderScene();
|
2018-09-23 21:17:31 +00:00
|
|
|
m_app->drawText3D("X", 1, 0, 0, 1);
|
|
|
|
m_app->drawText3D("Y", 0, 1, 0, 1);
|
|
|
|
m_app->drawText3D("Z", 0, 0, 1, 1);
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
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))
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
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);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!nSteps) nSteps = 1;
|
2015-04-16 16:55:32 +00:00
|
|
|
btVector3 prev = center + radiusA * vx * btCos(minAngle) + radiusB * vy * btSin(minAngle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (drawSect)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_app->m_renderer->drawLine(center, prev, color, lineWidth);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 1; i <= nSteps; i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
btScalar angle = minAngle + (maxAngle - minAngle) * btScalar(i) / btScalar(nSteps);
|
|
|
|
btVector3 next = center + radiusA * vx * btCos(angle) + radiusB * vy * btSin(angle);
|
2018-09-23 21:17:31 +00:00
|
|
|
m_app->m_renderer->drawLine(prev, next, color, lineWidth);
|
2015-04-16 16:55:32 +00:00
|
|
|
prev = next;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (drawSect)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_app->m_renderer->drawLine(center, prev, color, lineWidth);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
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);
|
2015-04-16 16:55:32 +00:00
|
|
|
//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);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-05-01 18:42:14 +00:00
|
|
|
|
|
|
|
virtual void resetCamera()
|
|
|
|
{
|
|
|
|
float dist = 3.5;
|
2017-06-01 22:30:37 +00:00
|
|
|
float pitch = -32;
|
|
|
|
float yaw = 136;
|
2018-09-23 21:17:31 +00:00
|
|
|
float targetPos[3] = {0, 0, 0};
|
|
|
|
if (m_app->m_renderer && m_app->m_renderer->getActiveCamera())
|
2015-05-01 18:42:14 +00:00
|
|
|
{
|
|
|
|
m_app->m_renderer->getActiveCamera()->setCameraDistance(dist);
|
|
|
|
m_app->m_renderer->getActiveCamera()->setCameraPitch(pitch);
|
|
|
|
m_app->m_renderer->getActiveCamera()->setCameraYaw(yaw);
|
2018-09-23 21:17:31 +00:00
|
|
|
m_app->m_renderer->getActiveCamera()->setCameraTargetPosition(targetPos[0], targetPos[1], targetPos[2]);
|
2015-05-01 18:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
CommonExampleInterface* CoordinateSystemCreateFunc(struct CommonExampleOptions& options)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2015-05-01 18:42:14 +00:00
|
|
|
return new CoordinateSystemDemo(options.m_guiHelper->getAppInterface());
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|