Operating System: : MacOS Mojave 10.14.4
Render System: : in Android Studio
Hi, I need help from ogre master.
I'm poor in English. Please understand.
First, I was able to compile and build samplebrowserNDK. I attached the bullet engine to the samplebrowserNDK and wrote the following code.
But, unlike my expectations, nothing is happening, only the ogre head and the floor. How do you get gravity to fall down?
Code: Select all
#ifndef __BulletTest_H__
#define __BulletTest_H__
#include "SdkSample.h"
#include "OgreSceneNode.h"
#include "btBulletDynamicsCommon.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btAlignedObjectArray.h"
#include "BulletDynamics/Dynamics/btDynamicsWorld.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
#include "BtOgrePG.h"
#include "BtOgreGP.h"
#include "BtOgreExtras.h"
using namespace Ogre;
using namespace OgreBites;
class _OgreSampleClassExport Sample_BulletTest : public SdkSample
{
public:
Sample_BulletTest()
{
mInfo["Title"] = "Bullet Test";
mInfo["Description"] = "Shows Bullet Gravity Test (fixed-distance domes used for backgrounds).";
mInfo["Thumbnail"] = "thumb_cubic.png";
mInfo["Category"] = "Environment";
}
protected:
void setupContent()
{
// setup some basic lighting for our scene
mSceneMgr->setAmbientLight(ColourValue(0.7, 0.7, 0.7));
mSceneMgr->getRootSceneNode()
->createChildSceneNode(Vector3(20, 80, 50))
->attachObject(mSceneMgr->createLight());
// set our camera to orbit around the origin and show cursor
mCameraMan->setStyle(CS_ORBIT);
mCameraMan->setYawPitchDist(Degree(0), Degree(0), 250);
mTrayMgr->showCursor();
///-----initialization_start-----
///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, -10, 0));
{
// create a floor mesh resource
MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Plane(Vector3::UNIT_Y, -50), 200, 200, 10, 10, true, 1, 8, 8, Vector3::UNIT_Z);
// create a floor entity, give it a material, and place it at the origin
Entity* mGroundEntity;
btRigidBody *mGroundBody;
btBvhTriangleMeshShape *mGroundShape;
mGroundEntity = mSceneMgr->createEntity("Floor", "floor");
mGroundEntity->setMaterialName("Examples/BumpyMetal");
mSceneMgr->getRootSceneNode()->createChildSceneNode("groudNode")->attachObject(mGroundEntity);
BtOgre::StaticMeshToShapeConverter converter2(mGroundEntity);
mGroundShape = converter2.createTrimesh();
//using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* mGroundState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));
//Create the Body.
mGroundBody = new btRigidBody(0, mGroundState, mGroundShape, btVector3(0,0,0));
dynamicsWorld->addRigidBody(mGroundBody);
}
{
Vector3 pos = Vector3(0,50,0);
Quaternion rot = Quaternion::IDENTITY;
SceneNode *mOgreNode;
Entity *mOgreEntity;
btRigidBody *mOgreBody;
btCollisionShape *mOgreShape;
mOgreEntity = mSceneMgr->createEntity("Head", "ogrehead.mesh");
mOgreNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("OgreSceneNode", pos, rot);
mOgreNode->attachObject(mOgreEntity);
//Create shape.
BtOgre::StaticMeshToShapeConverter converter(mOgreEntity);
mOgreShape = converter.createSphere();
//Calculate inertia.
btScalar mass = 5;
btVector3 inertia;
mOgreShape->calculateLocalInertia(mass, inertia);
//Create BtOgre MotionState (connects Ogre and Bullet).
BtOgre::RigidBodyState *mOgreState = new BtOgre::RigidBodyState(mOgreNode);
//Create the Body.
mOgreBody = new btRigidBody(mass, mOgreState, mOgreShape, inertia);
dynamicsWorld->addRigidBody(mOgreBody);
}
}
};
#endif