When I said I'd look at this tomorrow, what I meant to say is that I was going to stay up late and try and figure this out
I had a look at the model you sent me and the model that is shown on the screen is rotated 90 degrees from the information in the memblock.
Run this program and you'll see what I mean. This currently loads up the "powerplant.x" model, see the "LOAD_OBJECTS" sub-routine.
set window off
gosub SET_UP
gosub STARTING_VARIABLES
gosub LOAD_OBJECTS
`+++++ MAIN LOOP +++++++
_main_loop:
do
gosub CONTROLS
gosub DRAW_2D_BOX
gosub POSITION_CAMERA
gosub PRINT_STUFF
sync
loop
end
`+++++ SUB ROUTINES +++++++
SET_UP:
sync on
sync rate 60
hide mouse
autocam off
set camera range 1, 3000
cls
return
STARTING_VARIABLES:
zoom = -100
theta = 0
alpha = 0
return
LOAD_OBJECTS:
`load object and set it to wireframe
load object "powerplant.x", 1
set object 1,0,0,0
`create memblock from object and extract header info
make mesh from object 1,1
make memblock from mesh 1,1
format = memblock dword(1,0)
vert_size = memblock dword(1, 4)
num_verts = memblock dword(1, 8)
`make marker plain
make object plain 2, 1,1
hide object 2
`this makes a replica of object 1 by taking the vertex data and using this
`to make a ghosted model from triangles.
for i = 1 to num_verts/3
xa# = memblock float(1,12+(i-1)*vert_size*3)
ya# = memblock float(1,16+(i-1)*vert_size*3)
za# = memblock float(1,20+(i-1)*vert_size*3)
xb# = memblock float(1,44+(i-1)*vert_size*3)
yb# = memblock float(1,48+(i-1)*vert_size*3)
zb# = memblock float(1,52+(i-1)*vert_size*3)
xc# = memblock float(1,76+(i-1)*vert_size*3)
yc# = memblock float(1,80+(i-1)*vert_size*3)
zc# = memblock float(1,84+(i-1)*vert_size*3)
make object triangle i+2, xa#,ya#,za#, xb#,yb#,zb#, xc#,yc#,zc#
color object i+2, rgb(2500,0,0)
ghost object on i+2
next i
return
CONTROLS:
`this moves the camera around the object to give the
`effectt he object is rolling around (but it's not)
theta = wrapvalue(theta + mousemovex())
alpha = wrapvalue(alpha + mousemovey())
if mouseclick() = 1 then zoom = zoom + 3
if mouseclick() = 2 then zoom = zoom - 3
if zoom > -10 then zoom = -10
if spacekey() = 1 then gosub STARTING_VARIABLES
return
DRAW_2D_BOX:
if object in screen(1) = 1
x_object# = object position x(1)
y_object# = object position y(1)
z_object# = object position z(1)
`set the bounding box to zero
left = object screen x(1)
right = left
top = object screen y(1)
bottom = top
for i = 1 to num_verts
`extract the position of each vertex in 3D space
x# = memblock float(1,12+(i-1)*vert_size) + x_object# :`get the vertex x position in 3D space
y# = memblock float(1,16+(i-1)*vert_size) + y_object# :`get the vertex y position in 3D space
z# = memblock float(1,20+(i-1)*vert_size) + z_object# :`get the vertex z position in 3D space
`position the marker object at the vertex position in 3D space
position object 2, x#,y#,z#
x_screen = object screen x(2) :`get the screen x position of the marker object
y_screen = object screen y(2) :`get the screen y position of the marker object
`determine screen coordinates of bounding box
if x_screen < left then left = x_screen
if x_screen > right then right = x_screen
if y_screen < bottom then bottom = y_screen
if y_screen > top then top = y_screen
next i
`draw the bounding box
line left,top, right,top
line left,bottom, right,bottom
line left,top, left,bottom
line right,top, right,bottom
endif
return
POSITION_CAMERA:
position camera 0,0,0
yrotate camera theta
xrotate camera alpha
move camera zoom
return
PRINT_STUFF:
set cursor 0,0
print "Move mouse to view object. LMB to zoom in. RMB to zoom out."
print "Spacebar to reset view."
print
print "format : ", format
print "vertex size in bytes : ", vert_size
print "number of vertices in object : ", num_verts
return
The wireframe model is your model, the ghosted red object is created by taking the vertex data from the memblock and then contructs the model from triangle primitives. You can see that the ghost object is rotated 90 degree from the actual model.
This problem was cured when I loaded your model into blender and re-exported it as a .x file.
I also created some other models in blender but couldn't replicate the same issue that I was seeing with your model.
Is the email address you have in your profile current? If so I can email you the model I created and you can see if this works.