Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sip
engine
Commits
bb8297c5
Commit
bb8297c5
authored
Aug 25, 2018
by
D-AIRY
Browse files
Options
Downloads
Patches
Plain Diff
sxphysics small refactor
parent
f6fd4e99
No related branches found
No related tags found
1 merge request
!1
Version 0.10.1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
source/physics/PhyWorld.cpp
+39
-37
39 additions, 37 deletions
source/physics/PhyWorld.cpp
source/physics/PhyWorld.h
+15
-15
15 additions, 15 deletions
source/physics/PhyWorld.h
source/physics/sxphysics_dll.cpp
+11
-11
11 additions, 11 deletions
source/physics/sxphysics_dll.cpp
with
65 additions
and
63 deletions
source/physics/PhyWorld.cpp
+
39
−
37
View file @
bb8297c5
...
...
@@ -13,7 +13,7 @@ See the license in LICENSE
#include
<../Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h>
PhyWorld
::
PhyWorld
()
:
C
PhyWorld
::
C
PhyWorld
()
:
m_pGeomStaticCollideMesh
(
NULL
),
m_pGeomStaticCollideShape
(
NULL
),
m_pGeomStaticRigidBody
(
NULL
),
...
...
@@ -38,7 +38,7 @@ PhyWorld::PhyWorld():
Core_0RegisterCVarString
(
"phy_world_gravity"
,
"0 -10 0"
,
"World gravity (x y z)"
);
m_pDynamicsWorld
->
setGravity
(
btVector3
(
0
,
-
10
,
0
));
m_pDebugDrawer
=
new
DebugDrawer
();
m_pDebugDrawer
=
new
C
DebugDrawer
();
m_pDebugDrawer
->
setDebugMode
(
btIDebugDraw
::
DBG_DrawWireframe
);
//m_pDebugDrawer->setDebugMode(btIDebugDraw::DBG_FastWireframe);
m_pDynamicsWorld
->
setDebugDrawer
(
m_pDebugDrawer
);
...
...
@@ -48,9 +48,9 @@ PhyWorld::PhyWorld():
printf
(
"Done!
\n
"
);
}
PhyWorld
::~
PhyWorld
()
C
PhyWorld
::~
C
PhyWorld
()
{
U
nloadGeom
();
u
nloadGeom
();
mem_delete
(
m_pDynamicsWorld
);
mem_delete
(
m_pGHostPairCallback
);
...
...
@@ -60,19 +60,19 @@ PhyWorld::~PhyWorld()
mem_delete
(
m_pBroadphase
);
}
void
PhyWorld
::
render
()
void
C
PhyWorld
::
render
()
{
if
(
*
m_bDebugDraw
)
{
m_pDynamicsWorld
->
debugDrawWorld
();
((
DebugDrawer
*
)(
m_pDynamicsWorld
->
getDebugDrawer
()))
->
render
();
((
C
DebugDrawer
*
)(
m_pDynamicsWorld
->
getDebugDrawer
()))
->
render
();
}
}
void
PhyWorld
::
setThreadNum
(
int
tnum
)
void
C
PhyWorld
::
setThreadNum
(
int
tnum
)
{
}
void
PhyWorld
::
update
(
int
thread
)
void
C
PhyWorld
::
update
(
int
thread
)
{
if
(
!
m_isRunning
)
{
...
...
@@ -90,21 +90,21 @@ void PhyWorld::update(int thread)
time0
=
time1
;
}
void
PhyWorld
::
sync
()
void
C
PhyWorld
::
sync
()
{
}
void
PhyWorld
::
A
ddShape
(
btRigidBody
*
pBody
)
void
C
PhyWorld
::
a
ddShape
(
btRigidBody
*
pBody
)
{
m_pDynamicsWorld
->
addRigidBody
(
pBody
);
}
void
PhyWorld
::
addShape
(
btRigidBody
*
pBody
,
int
group
,
int
mask
)
void
C
PhyWorld
::
addShape
(
btRigidBody
*
pBody
,
int
group
,
int
mask
)
{
m_pDynamicsWorld
->
addRigidBody
(
pBody
,
group
,
mask
);
}
void
PhyWorld
::
R
emoveShape
(
btRigidBody
*
pBody
)
void
C
PhyWorld
::
r
emoveShape
(
btRigidBody
*
pBody
)
{
if
(
pBody
)
{
...
...
@@ -112,9 +112,9 @@ void PhyWorld::RemoveShape(btRigidBody * pBody)
}
}
void
PhyWorld
::
L
oadGeom
(
const
char
*
file
)
void
C
PhyWorld
::
l
oadGeom
(
const
char
*
file
)
{
if
(
file
&&
I
mportGeom
(
file
))
if
(
file
&&
i
mportGeom
(
file
))
{
return
;
}
...
...
@@ -185,7 +185,7 @@ void PhyWorld::LoadGeom(const char * file)
m_pGeomStaticRigidBody
->
setCollisionFlags
(
m_pGeomStaticRigidBody
->
getCollisionFlags
()
|
btCollisionObject
::
CF_DISABLE_VISUALIZE_OBJECT
);
m_pGeomStaticRigidBody
->
setFriction
(
100.0f
);
A
ddShape
(
m_pGeomStaticRigidBody
);
a
ddShape
(
m_pGeomStaticRigidBody
);
}
}
SGeom_ModelsClearArrBuffsGeom
(
ppVertices
,
pVertexCount
,
ppIndices
,
ppMtls
,
pIndexCount
,
iModelCount
);
...
...
@@ -379,7 +379,7 @@ void PhyWorld::LoadGeom(const char * file)
body
->
setCollisionFlags
(
body
->
getCollisionFlags
()
|
btCollisionObject
::
CF_DISABLE_VISUALIZE_OBJECT
);
body
->
setFriction
(
100.0f
);
A
ddShape
(
body
);
a
ddShape
(
body
);
}
}
}
...
...
@@ -388,16 +388,18 @@ void PhyWorld::LoadGeom(const char * file)
SGeom_GreenClearNavMeshAndTransform
(
green_arr_vertex
,
green_arr_count_vertex
,
green_arr_index
,
green_arr_mtl
,
green_arr_count_index
,
green_arr_transform
,
green_arr_count_transform
,
green_arr_count_green
);
if
(
file
)
ExportGeom
(
file
);
{
exportGeom
(
file
);
}
}
void
PhyWorld
::
U
nloadGeom
()
void
C
PhyWorld
::
u
nloadGeom
()
{
for
(
int
i
=
0
;
i
<
m_iGreenShapes
;
++
i
)
{
for
(
int
j
=
0
;
j
<
m_piGreenTotal
[
i
];
++
j
)
{
R
emoveShape
(
m_pppGreenStaticRigidBody
[
i
][
j
]);
r
emoveShape
(
m_pppGreenStaticRigidBody
[
i
][
j
]);
mem_delete
(
m_pppGreenStaticRigidBody
[
i
][
j
]);
}
mem_delete_a
(
m_pppGreenStaticRigidBody
[
i
]);
...
...
@@ -419,7 +421,7 @@ void PhyWorld::UnloadGeom()
R
emoveShape
(
m_pGeomStaticRigidBody
);
r
emoveShape
(
m_pGeomStaticRigidBody
);
mem_delete
(
m_pGeomStaticRigidBody
);
mem_delete
(
m_pGeomStaticCollideShape
);
mem_delete
(
m_pGeomStaticCollideMesh
);
...
...
@@ -429,9 +431,9 @@ void PhyWorld::UnloadGeom()
mem_delete_a
(
m_pGeomMtlIDs
);
}
bool
PhyWorld
::
I
mportGeom
(
const
char
*
file
)
bool
C
PhyWorld
::
i
mportGeom
(
const
char
*
file
)
{
U
nloadGeom
();
u
nloadGeom
();
int
len
=
strlen
(
file
)
+
1
;
char
*
name
=
(
char
*
)
alloca
(
sizeof
(
char
)
*
(
len
+
1
));
...
...
@@ -518,7 +520,7 @@ bool PhyWorld::ImportGeom(const char * file)
mem_delete
(
importer
);
if
(
!
ret
)
{
U
nloadGeom
();
u
nloadGeom
();
}
return
(
ret
);
}
...
...
@@ -530,7 +532,7 @@ const char * _allocStr(const char * _str)
return
(
str
);
}
bool
PhyWorld
::
E
xportGeom
(
const
char
*
_file
)
bool
C
PhyWorld
::
e
xportGeom
(
const
char
*
_file
)
{
btDefaultSerializer
*
serializer
=
new
btDefaultSerializer
();
serializer
->
startSerialization
();
...
...
@@ -583,9 +585,9 @@ bool PhyWorld::ExportGeom(const char * _file)
return
(
ret
);
}
MTLTYPE_PHYSIC
PhyWorld
::
G
etMtlType
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
)
MTLTYPE_PHYSIC
C
PhyWorld
::
g
etMtlType
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
)
{
ID
idMtl
=
G
etMtlID
(
pBody
,
pShapeInfo
);
ID
idMtl
=
g
etMtlID
(
pBody
,
pShapeInfo
);
if
(
ID_VALID
(
idMtl
))
{
return
(
SML_MtlGetPhysicMaterial
(
idMtl
));
...
...
@@ -593,7 +595,7 @@ MTLTYPE_PHYSIC PhyWorld::GetMtlType(const btCollisionObject *pBody, const btColl
return
(
MTLTYPE_PHYSIC_DEFAULT
);
}
ID
PhyWorld
::
G
etMtlID
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
)
ID
C
PhyWorld
::
g
etMtlID
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
)
{
if
(
pBody
==
m_pGeomStaticRigidBody
&&
m_iGeomFacesCount
>
pShapeInfo
->
m_triangleIndex
)
{
...
...
@@ -602,18 +604,18 @@ ID PhyWorld::GetMtlID(const btCollisionObject *pBody, const btCollisionWorld::Lo
return
(
-
1
);
}
void
PhyWorld
::
disableSimulation
()
void
C
PhyWorld
::
disableSimulation
()
{
m_isRunning
=
false
;
}
void
PhyWorld
::
enableSimulation
()
void
C
PhyWorld
::
enableSimulation
()
{
m_isRunning
=
true
;
}
//##############################################################
void
PhyWorld
::
DebugDrawer
::
drawLine
(
const
btVector3
&
from
,
const
btVector3
&
to
,
const
btVector3
&
color
)
void
C
PhyWorld
::
C
DebugDrawer
::
drawLine
(
const
btVector3
&
from
,
const
btVector3
&
to
,
const
btVector3
&
color
)
{
int
clr
=
0
;
clr
+=
255
;
...
...
@@ -635,12 +637,12 @@ void PhyWorld::DebugDrawer::drawLine(const btVector3 & from, const btVector3 & t
m_vDrawData
.
push_back
(
pt
);
}
void
PhyWorld
::
DebugDrawer
::
drawContactPoint
(
const
btVector3
&
PointOnB
,
const
btVector3
&
normalOnB
,
btScalar
distance
,
int
lifeTime
,
const
btVector3
&
color
)
void
C
PhyWorld
::
C
DebugDrawer
::
drawContactPoint
(
const
btVector3
&
PointOnB
,
const
btVector3
&
normalOnB
,
btScalar
distance
,
int
lifeTime
,
const
btVector3
&
color
)
{
}
void
PhyWorld
::
DebugDrawer
::
reportErrorWarning
(
const
char
*
warningString
)
void
C
PhyWorld
::
C
DebugDrawer
::
reportErrorWarning
(
const
char
*
warningString
)
{
if
(
m_bExpectObject
)
{
...
...
@@ -695,22 +697,22 @@ void PhyWorld::DebugDrawer::reportErrorWarning(const char * warningString)
LibReport
(
REPORT_MSG_LEVEL_WARNING
,
"%s"
,
warningString
);
}
void
PhyWorld
::
DebugDrawer
::
draw3dText
(
const
btVector3
&
location
,
const
char
*
textString
)
void
C
PhyWorld
::
C
DebugDrawer
::
draw3dText
(
const
btVector3
&
location
,
const
char
*
textString
)
{
}
void
PhyWorld
::
DebugDrawer
::
setDebugMode
(
int
debugMode
)
void
C
PhyWorld
::
C
DebugDrawer
::
setDebugMode
(
int
debugMode
)
{
m_iDebugMode
=
debugMode
;
}
int
PhyWorld
::
DebugDrawer
::
getDebugMode
()
const
int
C
PhyWorld
::
C
DebugDrawer
::
getDebugMode
()
const
{
return
(
m_iDebugMode
);
}
void
PhyWorld
::
DebugDrawer
::
render
()
void
C
PhyWorld
::
C
DebugDrawer
::
render
()
{
if
(
!
m_vDrawData
.
size
())
{
...
...
This diff is collapsed.
Click to expand it.
source/physics/PhyWorld.h
+
15
−
15
View file @
bb8297c5
...
...
@@ -37,42 +37,42 @@ struct PhyMatFile
};
#pragma pack(pop)
class
PhyWorld
class
C
PhyWorld
{
public:
PhyWorld
();
~
PhyWorld
();
C
PhyWorld
();
~
C
PhyWorld
();
void
setThreadNum
(
int
tnum
);
void
update
(
int
thread
=
0
);
void
sync
();
void
A
ddShape
(
btRigidBody
*
pBody
);
void
a
ddShape
(
btRigidBody
*
pBody
);
void
addShape
(
btRigidBody
*
pBody
,
int
group
,
int
mask
);
void
R
emoveShape
(
btRigidBody
*
pBody
);
void
r
emoveShape
(
btRigidBody
*
pBody
);
void
L
oadGeom
(
const
char
*
file
=
NULL
);
void
U
nloadGeom
();
void
l
oadGeom
(
const
char
*
file
=
NULL
);
void
u
nloadGeom
();
bool
I
mportGeom
(
const
char
*
file
);
bool
E
xportGeom
(
const
char
*
file
);
bool
i
mportGeom
(
const
char
*
file
);
bool
e
xportGeom
(
const
char
*
file
);
void
disableSimulation
();
void
enableSimulation
();
void
render
();
MTLTYPE_PHYSIC
G
etMtlType
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
);
MTLTYPE_PHYSIC
g
etMtlType
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
);
ID
G
etMtlID
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
);
ID
g
etMtlID
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
);
btDiscreteDynamicsWorld
*
G
etBtWorld
()
btDiscreteDynamicsWorld
*
g
etBtWorld
()
{
return
(
m_pDynamicsWorld
);
}
class
DebugDrawer
:
public
btIDebugDraw
class
C
DebugDrawer
:
public
btIDebugDraw
{
struct
render_point
{
...
...
@@ -84,7 +84,7 @@ public:
bool
m_bExpectObject
;
public
:
DebugDrawer
()
:
C
DebugDrawer
()
:
m_bExpectObject
(
false
)
{
}
...
...
@@ -113,7 +113,7 @@ protected:
btGhostPairCallback
*
m_pGHostPairCallback
;
const
bool
*
m_bDebugDraw
;
DebugDrawer
*
m_pDebugDrawer
;
C
DebugDrawer
*
m_pDebugDrawer
;
//
btTriangleMesh
*
m_pGeomStaticCollideMesh
;
...
...
This diff is collapsed.
Click to expand it.
source/physics/sxphysics_dll.cpp
+
11
−
11
View file @
bb8297c5
...
...
@@ -35,7 +35,7 @@ See the license in LICENSE
report_func
g_fnReportf
=
DefReport
;
#endif
PhyWorld
*
g_pWorld
=
NULL
;
C
PhyWorld
*
g_pWorld
=
NULL
;
#define SP_PRECOND(ret) if(!g_pWorld){LibReport(REPORT_MSG_LEVEL_ERROR, "%s - sxphysics is not init", GEN_MSG_LOCATION);return ret;}
...
...
@@ -64,7 +64,7 @@ SX_LIB_API void SXPhysics_0Create()
}
Core_SetOutPtr
();
g_pWorld
=
new
PhyWorld
();
g_pWorld
=
new
C
PhyWorld
();
}
SX_LIB_API
void
SXPhysics_AKill
()
{
...
...
@@ -96,13 +96,13 @@ SX_LIB_API void SXPhysics_Dbg_Set(report_func rf)
SX_LIB_API
void
SXPhysics_LoadGeom
(
const
char
*
file
)
{
SP_PRECOND
(
_VOID
);
g_pWorld
->
L
oadGeom
(
file
);
g_pWorld
->
l
oadGeom
(
file
);
}
SX_LIB_API
void
SXPhysics_UnloadGeom
()
{
SP_PRECOND
(
_VOID
);
g_pWorld
->
U
nloadGeom
();
g_pWorld
->
u
nloadGeom
();
}
SX_LIB_API
void
SXPhysics_DebugRender
()
...
...
@@ -114,7 +114,7 @@ SX_LIB_API void SXPhysics_DebugRender()
SX_LIB_API
void
SXPhysics_AddShape
(
btRigidBody
*
pBody
)
{
SP_PRECOND
(
_VOID
);
g_pWorld
->
A
ddShape
(
pBody
);
g_pWorld
->
a
ddShape
(
pBody
);
}
SX_LIB_API
void
SXPhysics_AddShapeEx
(
btRigidBody
*
pBody
,
int
group
,
int
mask
)
...
...
@@ -126,39 +126,39 @@ SX_LIB_API void SXPhysics_AddShapeEx(btRigidBody * pBody, int group, int mask)
SX_LIB_API
void
SXPhysics_RemoveShape
(
btRigidBody
*
pBody
)
{
SP_PRECOND
(
_VOID
);
g_pWorld
->
R
emoveShape
(
pBody
);
g_pWorld
->
r
emoveShape
(
pBody
);
}
SX_LIB_API
btDiscreteDynamicsWorld
*
SXPhysics_GetDynWorld
()
{
SP_PRECOND
(
NULL
);
return
(
g_pWorld
->
G
etBtWorld
());
return
(
g_pWorld
->
g
etBtWorld
());
}
SX_LIB_API
bool
SXPhysics_ImportGeom
(
const
char
*
file
)
{
SP_PRECOND
(
false
);
return
(
g_pWorld
->
I
mportGeom
(
file
));
return
(
g_pWorld
->
i
mportGeom
(
file
));
}
SX_LIB_API
bool
SXPhysics_ExportGeom
(
const
char
*
file
)
{
SP_PRECOND
(
false
);
return
(
g_pWorld
->
E
xportGeom
(
file
));
return
(
g_pWorld
->
e
xportGeom
(
file
));
}
SX_LIB_API
int
SXPhysics_GetMtlType
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
)
{
SP_PRECOND
(
MTLTYPE_PHYSIC_DEFAULT
);
return
(
g_pWorld
->
G
etMtlType
(
pBody
,
pShapeInfo
));
return
(
g_pWorld
->
g
etMtlType
(
pBody
,
pShapeInfo
));
}
SX_LIB_API
ID
SXPhysics_GetMtlID
(
const
btCollisionObject
*
pBody
,
const
btCollisionWorld
::
LocalShapeInfo
*
pShapeInfo
)
{
SP_PRECOND
(
-
1
);
return
(
g_pWorld
->
G
etMtlID
(
pBody
,
pShapeInfo
));
return
(
g_pWorld
->
g
etMtlID
(
pBody
,
pShapeInfo
));
}
SX_LIB_API
void
SXPhysics_EnableSimulation
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment