i see that the posts in the bullet forum have no explicit solutions.
not sure if the following will be useful in your problem. here:
to center a mesh. the mesh here is a pyramid. if we comment the call to ChangeMesh() in line 54 we will see the pyramid does not rotate around its own center, but with ChangeMesh() it will rotate around its center. note that the mesh are not in 0,0,0 position as in the modified code below. if we uncomment line 55 EntityPhysicBody(0,...) the pyramid will fall under gravity.
i don't understand the second question, but try to center the tree parts if this will correct the positions. i suggest to post a small working prototype of the problem may be someone will find a solution.
Code: Select all
Enumeration
#MESH
#LIGHT
#CAMERA
#mainwin
EndEnumeration
Structure Vector3
x.f
y.f
z.f
EndStructure
Define.Vector3 v1, v2, v3
Global x.f = 0
Global y.f = 10
Global z.f = -30
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "F2: wireframe. F3: solid ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define.f KeyX, KeyY
Declare ChangeMesh()
Declare CreateMatrix()
Declare DrawMatrix()
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
Add3DArchive("/", #PB_3DArchive_FileSystem)
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
MaterialShadingMode(0, #PB_Material_Wireframe )
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateMatrix()
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 120, #PB_Absolute)
CameraFOV(0, 70)
CameraBackColor(0, $330000)
CameraLookAt(0,0,0,0)
CreateLight(0, RGB(255,255,255), 10, 60, -10)
AmbientColor(RGB(90, 90, 90))
ChangeMesh()
;EntityPhysicBody(0, #PB_Entity_ConvexHullBody , 1, 0.5, 1)
Repeat
Event = WindowEvent()
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F2)
MaterialShadingMode(0, #PB_Material_Wireframe)
ElseIf KeyboardReleased(#PB_Key_F3)
MaterialShadingMode(0, #PB_Material_Solid)
EndIf
EndIf
rot.f+0.6
RotateEntity(0,0,rot,0)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure ChangeMesh()
Protected.f minx, miny, minz, maxx, maxy, maxz
Protected.f corx, cory, corz
minx = 999999
miny = 999999
minz = 999999
maxx = -999999
maxy = -999999
maxz = -999999
For i=0 To ArraySize(MeshData())
If MeshData(i)\x > maxx
maxx = MeshData(i)\x
EndIf
If MeshData(i)\x < minx
minx = MeshData(i)\x
EndIf
If MeshData(i)\y > maxy
maxy = MeshData(i)\y
EndIf
If MeshData(i)\y < miny
miny = MeshData(i)\y
EndIf
If MeshData(i)\z > maxz
maxz = MeshData(i)\z
EndIf
If MeshData(i)\z < minz
minz = MeshData(i)\z
EndIf
Next
corx = (-maxx - minx) /2.0
cory = (-maxy - miny) /2.0
corz = (-maxz - minz) /2.0
MessageRequester("", "minx = " + StrF(minx,2) + Chr(10) +
"miny = " + StrF(miny,2) + Chr(10) +
"minz = " + StrF(minz,2) + Chr(10) +
"maxx = " + StrF(maxx,2) + Chr(10) +
"maxy = " + StrF(maxy,2) + Chr(10) +
"maxz = " + StrF(maxz,2) + Chr(10) +
"Correction x = " + StrF(corx,2) + Chr(10) +
"Correction y = " + StrF(cory,2) + Chr(10) +
"Correction z = " + StrF(corz,2), #PB_MessageRequester_Ok )
For i=0 To ArraySize(MeshData())
MeshData(i)\x + corx
MeshData(i)\y + cory
MeshData(i)\z + corz
Next
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
EndProcedure
Procedure DrawMatrix()
MeshVertexPosition(-20, -20, -20) ;vertex 0
MeshVertexColor(RGB(255, 0, 0))
MeshVertexPosition(20, -20, -20) ; vertex 1
MeshVertexColor(RGB(0, 255, 0))
MeshVertexPosition(0, -20, -40) ; vertex 2
MeshVertexColor(RGB(255, 220, 0))
MeshVertexPosition(0, 10,-30) ; vertex 3
MeshFace(0, 1, 2)
MeshFace(1, 2, 3)
MeshFace(1, 0, 3)
MeshFace(0, 3, 2)
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #True)
DrawMatrix()
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(0))
CreateEntity(0, MeshID(0), #PB_Material_None, 45,15,-30)
ScaleEntity(0, 2, 2, 2)
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
GetMeshData(0,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(0, 0)-1)
EndProcedure