Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/ExampleBrowser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ ELSE(WIN32)
ENDIF(APPLE)
ENDIF(WIN32)

SET(myProjects
../myProjects/myTest/myTest.cpp
../myProjects/myTest/myTest.h
)

SET(ExtendedTutorialsSources
../ExtendedTutorials/Chain.cpp
Expand Down Expand Up @@ -434,8 +438,9 @@ ADD_EXECUTABLE(App_ExampleBrowser
main.cpp
ExampleEntries.cpp
ExampleEntries.h
${myProjects}
${ExtendedTutorialsSources}
${BulletExampleBrowser_SRCS}
${BulletExampleBrowser_SRCS}
)

FILE( MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/data" )
Expand Down
27 changes: 23 additions & 4 deletions examples/ExampleBrowser/CollisionShape2TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,29 @@ void CollisionShape2TriangleMesh(btCollisionShape* collisionShape, const btTrans
break;
}
case TRIANGLE_MESH_SHAPE_PROXYTYPE:
{
btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)collisionShape;
btVector3 trimeshScaling = trimesh->getLocalScaling();
btStridingMeshInterface* meshInterface = trimesh->getMeshInterface();
// ** btGImpactMeshShape has not created or empty graphic shape ** //
case GIMPACT_SHAPE_PROXYTYPE:
{
btStridingMeshInterface* meshInterface;
btVector3 trimeshScaling;
switch (collisionShape->getShapeType()) {
case TRIANGLE_MESH_SHAPE_PROXYTYPE:
{
btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)collisionShape;
trimeshScaling = trimesh->getLocalScaling();
meshInterface = trimesh->getMeshInterface();
break;
}
case GIMPACT_SHAPE_PROXYTYPE:
{
btGImpactMeshShape* imesh = (btGImpactMeshShape*)collisionShape;
trimeshScaling = imesh->getLocalScaling();
meshInterface = imesh->getMeshInterface();
break;
}
default:
break;
}
btAlignedObjectArray<btVector3> vertices;
btAlignedObjectArray<int> indices;

Expand Down
7 changes: 7 additions & 0 deletions examples/ExampleBrowser/ExampleEntries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
#include "../ExtendedTutorials/MultiPendulum.h"
#include "../Evolution/NN3DWalkers.h"


//myProjects
#include "../myProjects/myTest/myTest.h"

struct ExampleEntry
{
int m_menuLevel;
Expand All @@ -135,6 +139,9 @@ struct ExampleEntry

static ExampleEntry gDefaultExamples[] =
{
ExampleEntry(0, "myProjects"),
ExampleEntry(1, "myTest", "just a first test. ", ET_myTestCreateFunc),

ExampleEntry(0, "API"),

ExampleEntry(1, "Basic Example", "Create some rigid bodies using box collision shapes. This is a good example to familiarize with the basic initialization of Bullet. The Basic Example can also be compiled without graphical user interface, as a console application. Press W for wireframe, A to show AABBs, I to suspend/restart physics simulation. Press D to toggle auto-deactivation of the simulation. ", BasicExampleCreateFunc),
Expand Down
15 changes: 14 additions & 1 deletion examples/ExtendedTutorials/RigidBodyFromObj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,21 @@ void RigidBodyFromObjExample::initPhysics()
GLInstanceGraphicsShape* glmesh = LoadMeshFromObj(relativeFileName, "",&fileIO);
printf("[INFO] Obj loaded: Extracted %d verticed from obj file [%s]\n", glmesh->m_numvertices, fileName);


/*
* GLInstanceVertex and Renderer uses floats, not compatible data from btScalar this way if Double_Prec
*/
const GLInstanceVertex& v = glmesh->m_vertices->at(0);
btConvexHullShape* shape = new btConvexHullShape((const btScalar*)(&(v.xyzw[0])), glmesh->m_numvertices, sizeof(GLInstanceVertex));
//btConvexHullShape* shape = new btConvexHullShape((const btScalar*)(&(v.xyzw[0])), glmesh->m_numvertices, sizeof(GLInstanceVertex));
/* one solution is shape->addPoint in cycle */
btConvexHullShape* shape = new btConvexHullShape();
for (int i = 0; i < glmesh->m_numvertices; i++) {
shape->addPoint(btVector3(
glmesh->m_vertices->at(i).xyzw[0],
glmesh->m_vertices->at(i).xyzw[1],
glmesh->m_vertices->at(i).xyzw[2]
), false);
}

float scaling[4] = {0.1, 0.1, 0.1, 1};

Expand Down
25 changes: 16 additions & 9 deletions examples/OpenGLWindow/GLInstancingRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct caster2
#include "LoadShader.h"

#include "GLInstanceRendererInternalData.h"
#include "GLInstanceGraphicsShape.h"

//GLSL shader strings, embedded using build3/stringify
#include "Shaders/pointSpriteVS.h"
Expand Down Expand Up @@ -397,6 +398,12 @@ GLInstancingRenderer::GLInstancingRenderer(int maxNumObjectCapacity, int maxShap
m_data->m_instance_quaternion_ptr.resize(m_data->m_maxNumObjectCapacity * 4);
m_data->m_instance_colors_ptr.resize(m_data->m_maxNumObjectCapacity * 4);
m_data->m_instance_scale_ptr.resize(m_data->m_maxNumObjectCapacity * 4);

GLInstanceVertex* calc_pos = new GLInstanceVertex();
pos_xyzw = reinterpret_cast<float *>(calc_pos->xyzw) - reinterpret_cast<float *>(calc_pos);
pos_normal = reinterpret_cast<float *>(calc_pos->normal) - reinterpret_cast<float *>(calc_pos);
pos_uv = reinterpret_cast<float *>(calc_pos->uv) - reinterpret_cast<float *>(calc_pos);
delete calc_pos;
}

void GLInstancingRenderer::removeAllInstances()
Expand Down Expand Up @@ -1147,7 +1154,7 @@ void GLInstancingRenderer::updateShape(int shapeIndex, const float* vertices, in
return;

glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
int vertexStrideInBytes = 9 * sizeof(float);
int vertexStrideInBytes = sizeof(GLInstanceVertex); // 9 * sizeof(float);
int sz = numvertices * vertexStrideInBytes;
#if 0
char* dest= (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_WRITE_ONLY);//GL_WRITE_ONLY
Expand Down Expand Up @@ -1186,7 +1193,7 @@ int GLInstancingRenderer::registerShape(const float* vertices, int numvertices,
gfxObj->m_numIndices = numIndices;
gfxObj->m_numVertices = numvertices;

int vertexStrideInBytes = 9 * sizeof(float);
int vertexStrideInBytes = sizeof(GLInstanceVertex); // 9 * sizeof(float);
int sz = numvertices * vertexStrideInBytes;
int totalUsed = vertexStrideInBytes * gfxObj->m_vertexArrayOffset + sz;
b3Assert(totalUsed < m_data->m_maxShapeCapacityInBytes);
Expand Down Expand Up @@ -2478,25 +2485,25 @@ void GLInstancingRenderer::renderSceneInternal(int orgRenderMode)

glBindVertexArray(gfxObj->m_cube_vao);

int vertexStride = 9 * sizeof(float);
int vertexStride = sizeof(GLInstanceVertex); // 9 * sizeof(float);
PointerCaster vertex;
vertex.m_baseIndex = gfxObj->m_vertexArrayOffset * vertexStride;
vertex.m_baseIndex = gfxObj->m_vertexArrayOffset * vertexStride + pos_xyzw*sizeof(float);

//vertex position
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 9 * sizeof(float), vertex.m_pointer);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, vertexStride, vertex.m_pointer);
//instance_position
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(transparentInstances[i].m_instanceId * 4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes));
//instance_quaternion
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(transparentInstances[i].m_instanceId * 4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE));

PointerCaster uv;
uv.m_baseIndex = 7 * sizeof(float) + vertex.m_baseIndex;
uv.m_baseIndex = gfxObj->m_vertexArrayOffset * vertexStride + pos_uv*sizeof(float);

PointerCaster normal;
normal.m_baseIndex = 4 * sizeof(float) + vertex.m_baseIndex;
normal.m_baseIndex = gfxObj->m_vertexArrayOffset * vertexStride + pos_normal*sizeof(float);

glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 9 * sizeof(float), uv.m_pointer);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), normal.m_pointer);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, vertexStride, uv.m_pointer);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, vertexStride, normal.m_pointer);
//instance_color
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(transparentInstances[i].m_instanceId * 4 * sizeof(float) + m_data->m_maxShapeCapacityInBytes + POSITION_BUFFER_SIZE + ORIENTATION_BUFFER_SIZE));
//instance_scale
Expand Down
3 changes: 3 additions & 0 deletions examples/OpenGLWindow/GLInstancingRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class GLInstancingRenderer : public CommonRenderInterface
int m_screenWidth;
int m_screenHeight;

// distance in GLInstanceVertex struct ( in floats )
int pos_xyzw, pos_normal, pos_uv;

int m_upAxis;

int m_planeReflectionShapeIndex;
Expand Down
25 changes: 25 additions & 0 deletions examples/myProjects/myTest/myTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "myTest.h"

#include "../../CommonInterfaces/CommonRigidBodyBase.h"

struct myTest: public CommonRigidBodyBase
{
int m_options;

myTest(struct GUIHelperInterface* helper, int options)
: CommonRigidBodyBase(helper),
m_options(options)
{
}
virtual ~myTest() {}
virtual void initPhysics() {}
virtual void renderScene() {}
void resetCamera() {}
};

CommonExampleInterface* ET_myTestCreateFunc(CommonExampleOptions& options)
{
return new myTest(options.m_guiHelper, options.m_option);
}

B3_STANDALONE_EXAMPLE(ET_myTestCreateFunc)
6 changes: 6 additions & 0 deletions examples/myProjects/myTest/myTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef ET_MYTEST_H
#define ET_MYTEST_H

class CommonExampleInterface* ET_myTestCreateFunc(struct CommonExampleOptions& options);

#endif