add RenderDemo to CpuDemo.
This commit is contained in:
51
Demos3/CpuDemos/rendering/RenderDemo.cpp
Normal file
51
Demos3/CpuDemos/rendering/RenderDemo.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "RenderDemo.h"
|
||||
#include "OpenGLWindow/GLInstancingRenderer.h"
|
||||
#include "OpenGLWindow/ShapeData.h"
|
||||
#include "Bullet3Common/b3Quaternion.h"
|
||||
|
||||
|
||||
static b3Vector4 colors[4] =
|
||||
{
|
||||
b3MakeVector4(1,0,0,1),
|
||||
b3MakeVector4(0,1,0,1),
|
||||
b3MakeVector4(0,1,1,1),
|
||||
b3MakeVector4(1,1,0,1),
|
||||
};
|
||||
|
||||
|
||||
void RenderDemo::initPhysics(const ConstructionInfo& ci)
|
||||
{
|
||||
m_instancingRenderer = ci.m_instancingRenderer;
|
||||
|
||||
int strideInBytes = 9*sizeof(float);
|
||||
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(cube_indices)/sizeof(int);
|
||||
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
|
||||
b3Vector3 position = b3MakeVector3(0,0,0);//((j+1)&1)+i*2.2,1+j*2.,((j+1)&1)+k*2.2);
|
||||
b3Quaternion orn(0,0,0,1);
|
||||
|
||||
static int curColor=0;
|
||||
b3Vector4 color = colors[curColor];
|
||||
curColor++;
|
||||
curColor&=3;
|
||||
b3Vector4 scaling=b3MakeVector4(1,1,1,1);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
|
||||
ci.m_instancingRenderer->writeTransforms();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RenderDemo::exitPhysics()
|
||||
{
|
||||
}
|
||||
|
||||
void RenderDemo::renderScene()
|
||||
{
|
||||
m_instancingRenderer->renderScene();
|
||||
}
|
||||
|
||||
void RenderDemo::clientMoveAndDisplay()
|
||||
{
|
||||
}
|
||||
36
Demos3/CpuDemos/rendering/RenderDemo.h
Normal file
36
Demos3/CpuDemos/rendering/RenderDemo.h
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
#include "../CpuDemo.h"
|
||||
|
||||
struct RenderDemo : public CpuDemo
|
||||
{
|
||||
GLInstancingRenderer* m_instancingRenderer;
|
||||
|
||||
virtual void initPhysics(const ConstructionInfo& ci);
|
||||
|
||||
virtual void exitPhysics();
|
||||
|
||||
virtual void renderScene();
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
virtual const char* getName() {
|
||||
return "RenderDemo";
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
static CpuDemo* MyCreateFunc()
|
||||
{
|
||||
CpuDemo* demo = new RenderDemo;
|
||||
return demo;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user