Hi,
I have a problem with object bounds.
I modify an object vertices and i try to recalculate object bounds otherwise the camera considers the object out of the field of view when it's on its edge.
I made a small code to explain(db pro v1.0761) :
Rem Project: Objets bounds
Rem Created: Tuesday, February 24, 2015
Rem ***** Main Source File *****
#CONSTANT FALSE=0
#CONSTANT TRUE=1
sync on
autocam off
make object plain 1,10,10
xrotate object 1,-90
color object 1,rgb(255,0,0)
set object wireframe 1,1
//start A --------------------------------------------------
show_bounds=TRUE
show object bounds 1
//end A --------------------------------------------------
//start B --------------------------------------------------
//offset_vertices(1,15)
//calculate object bounds 1
//end B --------------------------------------------------
position camera 0,20,-40
do
text 0,0,"UPKEY : camera_y=camera_y+0.1"
text 0,12,"DOWNKEY : camera_y=camera_y-0.1"
text 0,24,"RETURNKEY : increase vertices y position by 1"
text 0,36,"SPACEKEY : recalculate object bounds"
text 0,48,"CONTROLKEY : show/hide object bounds"
if upkey() and timer()>timer_y+50
position camera camera position x(),camera position y()+0.5,camera position z()
timer_y=timer()
endif
if downkey() and timer()>timer_y+50
position camera camera position x(),camera position y()-0.5,camera position z()
timer_y=timer()
endif
if returnkey() and timer()>timer_offset+200
timer_offset=timer()
offset_vertices(1,15)
endif
if spacekey()
calculate object bounds 1
endif
if controlkey()
if control=FALSE
control=TRUE
if show_bounds=TRUE
hide object bounds 1
show_bounds=FALSE
else
show object bounds 1
show_bounds=TRUE
endif
endif
else
control=FALSE
endif
rotate camera camera angle x()+mousemovey(),camera angle y()+mousemovex(),0
sync
loop
function offset_vertices(object,offset)
lock vertexdata for limb object,0,0
for vertex=0 to get vertexdata vertex count()-1
set vertexdata position vertex,get vertexdata position x(vertex),get vertexdata position y(vertex),get vertexdata position z(vertex)+offset
next vertex
unlock vertexdata
endfunction
how to test :
test 1:
Start the default program (part A not commented and part B commented).
Push return once, you will see the object get higher.(object's coordinates are actually still 0,0,0. All individual vertices have been offset by 15)
if you aim the camera up with the mouse, the object should disappear before it leaves the screen at the bottom, the camera considering it's still down there.
you can push space to recalculate object bounds or hide and show them with control. It won't refresh
test 2:
Set part A and B as comments so the bounds are not shown at start
push return once
push space to calculate bounds and then control to display them.
you will see the the new bounds are correct but the "object disappearing" problem remains
test 3:
Set part B uncommented and keep part A commented
This will offset the vertices by 15 and recalculate the bounds which is what we did manually so far. But the fact that it's done before setting the camera position solve the screen edge problem.
if you move camera up and down the object should not disappear
controlkey should display the correct bounds as long as you don't move the vertices with return
If anyone knows how i could modify vertices and recalculate bounds after repositioning the camera that would help me a lot.
Any advice might help, thanks for testing.
Bye