Skip to content

Commit

Permalink
修复地形单元无法碰撞的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
cgoxopx committed May 10, 2019
1 parent 34bd217 commit cae8b83
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 59 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ Please install irrlicht,bullet3,lua5.1 and raknet at first,and then run `make` i
## Run:
### run server:
`./server`
default port is `39065`
And then server will run on `39065` port
### create a user:
run `./admin --adminName admin --password 1234 --mode createUser --X 0 --Y 100 --Z 0 --nsid 1 --npwd userPassword`
This commond will create a new user and show the UUID of new user and it will be used in next step.
### run client:
`./client 127.0.0.1 39065 yourUUID yourPassword`
`./client 127.0.0.1 39065 [yourUUID] [yourPassword]`
### teleport player:
`./admin --adminName admin --password 1234 --mode teleport --X 2000 --Y 900 --Z 2000 --substance [substance uuid]`
## View:
![img](./screenshot/2019-03-12-23-09-36.png)
![img](./screenshot/2019-05-10-17-26-15.png)
Binary file added screenshot/2019-05-10-17-26-15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,20 @@ static int mod_addSubstance(lua_State * L){
b->noFallDown=lua_toboolean(L,-1);
}
lua_pop(L,1);

lua_pushstring(L,"walkInSky");
lua_gettable(L,-2);
if(lua_isboolean(L,-1)){
b->walkInSky=lua_toboolean(L,-1);
}
lua_pop(L,1);

lua_pushstring(L,"jumpInSky");
lua_gettable(L,-2);
if(lua_isboolean(L,-1)){
b->jumpInSky=lua_toboolean(L,-1);
}
lua_pop(L,1);
}
lua_pop(L,1);

Expand Down
6 changes: 6 additions & 0 deletions src/mods.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ namespace smoothly{
float friction;//摩擦力
float restitution;//反弹

bool walkInSky;
bool jumpInSky;

std::string bodyType;//rigid,character,vehicle , default is rigid

float characterWidth,characterHeight;
Expand Down Expand Up @@ -194,6 +197,9 @@ namespace smoothly{
hitTerrainItemCallback=0;
hitTerrainCallback=0;

walkInSky=false;
jumpInSky=false;

haveHitSubsCallback=false;
haveHitBuildingCallback=false;
haveHitTerrainItemCallback=false;
Expand Down
14 changes: 11 additions & 3 deletions src/physical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,12 @@ void physical::bodyBase::setDir(const irr::core::vector3df & d){
setRotation(rotate);
}

physical::character::character(btScalar w,btScalar h,const btVector3 & position,btScalar stepHeight){
printf("[body]create character\n");
physical::character::character(btScalar w,btScalar h,const btVector3 & position,bool wis,bool jis,btScalar stepHeight){
//printf("[body]create character\n");

walkInSky=wis;
jumpInSky=jis;

shape = new btCapsuleShape(w,h);

btTransform m_trans;
Expand Down Expand Up @@ -430,9 +434,13 @@ void physical::character::removeFromWorld(){
}
void physical::character::setWalkDirection(const btVector3& walkDirection){
//printf("[character]walk (%f,%f,%f)\n",walkDirection.getX(),walkDirection.getY(),walkDirection.getZ());
if(!walkInSky && !controller->onGround())
return;
controller->setWalkDirection(walkDirection);
}
void physical::character::jump(const btVector3& dir){
if(!jumpInSky && !controller->onGround())
return;
controller->jump(dir);
}
void physical::character::setUserPointer(void * p){
Expand All @@ -448,7 +456,7 @@ physical::rigidBody::rigidBody(
btScalar mass ,
const btVector3& localInertia
){
printf("[body]create rigid body\n");
//printf("[body]create rigid body\n");
bodyState=new btDefaultMotionState(transform);
body=createBody(bodyShape , bodyState , mass , localInertia);
}
Expand Down
11 changes: 10 additions & 1 deletion src/physical.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,16 @@ namespace smoothly{
btKinematicCharacterController * controller;
btPairCachingGhostObject * m_ghostObject;
btConvexShape* shape;
character(btScalar w,btScalar h,const btVector3 & position,btScalar stepHeight = btScalar(0.35));
bool walkInSky;
bool jumpInSky;
character(
btScalar w,
btScalar h,
const btVector3 & position,
bool wis,
bool jis,
btScalar stepHeight = btScalar(0.35)
);
virtual void destruct();
virtual void addIntoWorld();
virtual void removeFromWorld();
Expand Down
1 change: 1 addition & 0 deletions src/subsServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void subsServer::teleport(
//set database
p->save(false,true);
moveUserPosition(uuid,p->userUUID,posi);
//printf("[subsServer]teleport substance %s to (%f,%f,%f)\n",p->userUUID.c_str(),posi.X,posi.Y,posi.Z);
}
p->drop();
}
Expand Down
53 changes: 4 additions & 49 deletions src/substance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,55 +169,9 @@ void substance::subs::move(const irr::core::vector3df & delta){
body->setWalkDirection(btVector3(delta.X , delta.Y , delta.Z));
}
void substance::subs::teleport(const irr::core::vector3df & p){
//printf("[substance]teleport substance %s to (%f,%f,%f)\n",uuid.c_str(),p.X,p.Y,p.Z);
body->teleport(p);
}
void substance::subs::checkPosition(){
if(!inWorld)
return;

bool flag=false;

btTransform transform;
body->getTransform(transform);
btVector3 position = transform.getOrigin();

if(position.getX()<-65535){
position.setX(-65535);
flag=true;
}else
if(position.getX()>65535){
position.setX(65535);
flag=true;
}

if(position.getZ()<-65535){
position.setZ(-65535);
flag=true;
}else
if(position.getZ()>65535){
position.setZ(65535);
flag=true;
}

if(position.getY()<-50){
position.setY(-50);
flag=true;
}else
if(position.getY()>500){
position.setY(500);
flag=true;
}else{
auto h=parent->getRealHight(position.getX(),position.getZ());
if(position.getY()<h){
position.setY(h);
flag=true;
}
}

if(flag){
body->setTransform(transform);
}
}
void substance::subs::setPosition(const irr::core::vector3df & p){
body->setPosition(p);

Expand Down Expand Up @@ -293,7 +247,6 @@ void substance::subsUpdate(){
for(auto it:subses){
//update collision
it.second->update();//update scene
//it.second->checkPosition();
}
parseAllCommond();
}
Expand Down Expand Up @@ -526,7 +479,9 @@ void substance::subs::init(mods::subsConf * conf,const irr::core::vector3df & p,
body=new character(
conf->characterWidth ,
conf->characterHeight ,
btVector3(p.X , p.Y , p.Z)
btVector3(p.X , p.Y , p.Z),
conf->walkInSky ,
conf->jumpInSky
);
}else{
printf("[substance]create rigid body:%s\n",uuid.c_str());
Expand Down
1 change: 0 additions & 1 deletion src/substance.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ namespace smoothly{
void release();

void setAsBrief(int life);
void checkPosition();
void update();

bool addIntoWorld();
Expand Down
6 changes: 4 additions & 2 deletions src/terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,10 @@ int terrain::chunk::add(
ptr->node->setName(buf);

if(mit->second->bodyShape){
ptr->node->updateAbsolutePosition();
ptr->bodyState=setMotionState(ptr->node->getAbsoluteTransformation().pointer());
auto dp=ptr->nodeLOD[0]->getPosition();
//printf("[terrain::chunk]add body(%f,%f,%f)\n",dp.X,dp.Y,dp.Z);
ptr->nodeLOD[0]->updateAbsolutePosition();
ptr->bodyState=setMotionState(ptr->nodeLOD[0]->getAbsoluteTransformation().pointer());
//btTransform transform;
ptr->rigidBody=createBody(mit->second->bodyShape,ptr->bodyState);
ptr->rigidBody->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);
Expand Down

0 comments on commit cae8b83

Please sign in to comment.