Might be useful to someone, this is equivalent of DBPro commands float=Collision Center X/Y/Z. Thanks to the user that provided the AutoCam function, I can't recall top of my head, but thanks, saved me from "re-inventing the wheel". Code makes use of vector3 math commands.
[edit]- ok forgot to cleanup, added code to delete memblock and vectors, kept object in for display only.
// Project: collision_center_xyz
// Created: 2022-02-24
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "collision_center_xyz" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
INFINITY# = 3.4E38
`oid=CreateObjectBox(10,10,10)
oid=LoadObjectWithChildren("door_g_quat.x")
mid=CreateMemblockFromObjectMesh(oid,1)
minPt = createvector3()
maxPt = createvector3()
center = createvector3()
setvector3(minPt,INFINITY#,INFINITY#,INFINITY#)
setvector3(maxPt,-INFINITY#,-INFINITY#,-INFINITY#)
setvector3(center,0.0,0.0,0.0)
GetVector3Add(maxPt,minPt)
GetVector3Add(center,maxPt)
xmin#=GetVector3X(minPt) : ymin#=GetVector3Y(minPt) : zmin#=GetVector3Z(minPt)
xmax#=GetVector3X(maxPt) : ymax#=GetVector3Y(maxPt) : zmax#=GetVector3Z(maxPt)
xcen#=GetVector3X(center) : ycen#=GetVector3Y(center) : zcen#=GetVector3Z(center)
GetVector3Multiply (center,0.5)
vc = GetMemblockInt(mid,0)
x as float : y as float : z as float
minx as float : miny as float : minz as float
maxx as float : maxy as float : maxz as float
for v = 0 to vc
x = GetMeshMemblockVertexX( mid, v )
y = GetMeshMemblockVertexY( mid, v )
z = GetMeshMemblockVertexZ( mid, v )
if x < minx then minx=x
if y < miny then miny=y
if z < minz then minz=z
if x > maxx then maxx=x
if y > maxy then maxy=y
if z > maxz then maxz=z
next v
setvector3(minPt,minx,miny,minz)
setvector3(maxPt,maxx,maxy,maxz)
setvector3(center,0.0,0.0,0.0)
GetVector3Add(maxPt,minPt)
GetVector3Add(center,maxPt)
GetVector3Multiply (center,0.5)
xcen#=GetVector3X(center) : ycen#=GetVector3Y(center) : zcen#=GetVector3Z(center)
AutoCam(oid)
do
Print( ScreenFPS() )
Print ("#verts: "+str(vc))
PrintC ("Minx: "+str(minx)) : PrintC (" Maxx: "+str(maxx))
Print (" Miny: "+str(miny)) : PrintC ("Maxy: "+str(maxy)) :
PrintC (" Minz: "+str(minz)) : PrintC (" Maxz: "+str(maxz))
Print ("")
PrintC ("colX: "+str(xcen#)) : PrintC (" colY: "+str(ycen#)) : PrintC (" colZ: "+str(zcen#))
Sync()
loop
function AutoCam(obj as integer)
sx# = GetObjectSizeMaxX(obj)
sy# = GetObjectSizeMaxY(obj)
sz# = GetObjectSizeMaxZ(obj)
r# = sqrt(sx#*sx# + sy#*sy# + sz#*sz#)
x# = getobjectx(obj)
y# = getobjecty(obj)
z# = getobjectz(obj)
SetCameraPosition(1, x#, y# + (r#/2.0), z# - (r#*3.0))
SetCameraLookAt(1, x#, y#, z#, 0.0)
endfunction
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others