Best way to scale and rotate Models ?

Blitz3D Forums/Blitz3D Beginners Area/Best way to scale and rotate Models ?

StOrM3(Posted 2004) [#1]
Hello,

Back again with a wierd problem, okay I have been using rotateentity and scaleentity, and have ran into a snag when using these the object placement on the screen is not correct, and the collision with the level as the objects fall down to land on the level with random x,z positions using the dropping method to set the y coord, it is not coming out right and some objects fall through the level. I believe that if I use scalemesh and rotatemesh instead this will fix this issue, any thoughts, examples on how to make the collision work and position the entities 50 pixels apart exactly and rotated a little would be great. Thanks.

Ken


_PJ_(Posted 2004) [#2]
ScaleEntity does not affect collision radius - I know that much - it's quite annoying.

I assume ScaleMesh would, but not definite on that!


jhocking(Posted 2004) [#3]
Actually, I'm fairly certain ScaleMesh does not affect collision radius. The collision radius is set with EntityRadius.


Ross C(Posted 2004) [#4]
Your maybe making the entities fall too fast. I had a run in with that. Also, if you rotate abjects and collide, it causes problems. And if you move the item to be collided against, this also causes collision probelms.

Make sure as well that your doing the collisions the right way round. The moving entity always has to be the first entity, and the other one, the second (and stationary) one.

Collisions first_entity,second_entity,2,2



StOrM3(Posted 2004) [#5]
Okay and question, where would be best to call collisions ? In main game loop, outside it, it only has to be called once right ? Or should I put it inside my Dropitems function, so everytime they move, it checks for a collision or is it auto after you define the collisions and the collision type of each entity etc..?


N(Posted 2004) [#6]
I call it in the main loop (specifically, I call it from a function, but that's in the main loop). As far as I know that's where it should be called since UpdateWorld() also tends to be in the main loop...

I'd suggest putting it in your DropItems function and calling that only once per loop.

Also, Ross, it's
Collisions First_Entity's_Type,Second_Entity's_Type,2,2


Not entities in specific :)


Ross C(Posted 2004) [#7]
Don't get smart with me sucka!

hehe, yeah, just noticed that, sorry :)


StOrM3(Posted 2004) [#8]
Okay what is the gist of this function, all it does is tell blitz3d to look for collisions and stop the ones between these two types correct ? Okay if that is the case we fall back on the other prob someone stated above that scalemesh and scaleentity would not increase the bounding box size etc.. needed for collisions, so once I do a scalemesh item,2,2,2 to double its size, how do I then get the items size to use in either boxset or setradius which ever to use not sure of the exact function names. What I want to do, and I coded a function yesterday based off what you told me, to load the mesh, rotate the mesh, instead of scale anything, I used fitmesh and specified the box size I wanted the fruit to fit inside, true to scale in all dims. Then finished setting the other params, this is when I initially load the models, does that mean, when I use copymesh does the new size, bounding box etc.. come with it when copying it ? If so i think I got it straight finally.. sorry for all the trouble, but this is a major point for any game, I had everything displaying just fine, and player movement somewhat worked, then I needed to fix the dims between items and then you run into other problems because stuff wasn't done correctly the first time. <g>. BTW: Does anyone know what all new funcs are in the new blitz update as well ? Something else I thought about is maybe using the Coldet wrapper lib, any thoughts on this, how easy / hard it would be to use for something like this ?

Thanks again for all your hardwork,

Ken


Ross C(Posted 2004) [#9]
CopyEntity should copy bounding boxes and such. Copy mesh only copies mesh information. No texture, no collision information, and no parent information if i remember correctly.

Anytime you scale entity, you need to scale the bounding box. Only thing about scalemesh, is that the scale is a mulitple of it's current size. So

ScaleMesh mesh,2,2

ScaleMesh mesh,2,2


would make the mesh 4 times it's size

ScaleEntity mesh,2,2

ScaleEntity mesh,2,2


would make the entity 2 times it's size, because it always takes the orginal size. ScaleMesh changes the mesh information, ScaleEntity doesn't.


StOrM3(Posted 2004) [#10]
Okay, how about a line of code showing how to scale the bounding box to the same size as the item we just scaled. I mean how to do it, without knowing the exact model size of the model we just loaded in, say we load one, scale it by 2, then how can we read its current size info, then adjust the bounding box accordingly ? Also, I have another interesting prob, I need to use polygon collision detection on the level, unless, I load the floor and the walls around it seperately, since the floor needs to have a bounding box and so do the walls of the arena. hmmmm..
That may be a major part of the bug I have now, since if I just use a box or capsule collision, it would be the size of the floor and height of walls large, so the items should theoretically stop at the top edge of the walls, not the desired affect. Sorry just thinking out loud, I do appreciate all the help though.

Ken


Ross C(Posted 2004) [#11]
Unfortunlty you can't get the number the model has been scaled. You need to store this yourself.

Create the box so it fits the mesh.
Store the amount the entity has been scaled.
Use this number and multiple the collision box boundries by it.

scale=2

entitybox mesh,x,y,z,width*scale,height*scale,depth*scale

something like that.


StOrM3(Posted 2004) [#12]
yes but isn't there a way to get the width, depth and height of the mesh I load in ? Like to retrieve the models original dimensions when I load it using loadmesh, get the dims, then store those to use to scale the bounding box to the correct size etc ??

I have an example function I want you to check and see if it will work like I think.. I will post it here in a moment.

Ken


StOrM3(Posted 2004) [#13]
; Here it is, pardon, my lack of comments as I did this
; work between calls...
function setupfruit%()
local count%=1

local meshx#, meshy#, meshz#
local sizex#, sizey#, sizez#

for count% = 1 to 7
if count% = 1 then
fruitarray(count%)\fmodel% = loadmesh("../media/cherry.b3d")
meshx# = entityx(fruitarray(count%)\fmodel%,true)
meshy# = entityy(fruitarray(count%)\fmodel%,true)
meshz# = entityz(fruitarray(count%)\fmodel%,true)
rotatemesh(fruitarray(count%)\fmodel%,60,30,0) ; Rotate the mesh after loading it.
fitmesh(fruitarray(count%)\fmodel%, meshx#, meshy#, meshz#, 15.0, 15.0, 15.0, true)
fruitarray(count%)\number% = count%
fruitarray(count%)\name$ = "cherry"
NameEntity fruitarray(count%)\fmodel%, "cherry"
endif
;fill in like above for other fruit... Next remove all scaling and rotation code from
;level setup functions and dropitems!
next
end function

; IDEAS
;Remember to use the entityname now to test for collisions
;between items.
;Also, remember to set a name for Level and Player also,
;to make it easy to check for collisions,
;and remember to setup the collision boxes for level and
;player as well, also generally clean up code
;and update the comments to match the current code base
;state.

; Next: Work on mouse code once all other fruit
; problems /
; glitches are repaired and perfectly displayed.

PS thanks for all your help!


StOrM3(Posted 2004) [#14]
Nobody, has any suggestions or knows if this will work as intended ? Ross are you still lurking ? Sorry for the impatience, but I am at work, kinda bored and wanted to get some work done on this, I want to get a prototype done and ready for beta testing in the next week.

Thanks again, for all the help. Also if you have any ideas about how to setup the bounding boxes for the floor and walls of the level, so that the fruit models will collide with the floor and stop there, since the walls are on all four sides of the floor and stand taller than the floor, kind of as a containment area, and I drop the fruit models from above, going -20 in the y coord til they hit the floor model, but if I use normal bounding box for the whole level model I believe the fruit will stop at the top edge of the walls instead of down further to the floor level.

Ideas ? Code Samples ?


StOrM3(Posted 2004) [#15]
Hey, I just had an idea, does anyone know of an editor to allow you to move and size and draw bounding boxes and then allow you to output the data to a txt or ini file of some sort that I could use to manually setup the bounding boxes for the level ? I still want to do the bounding boxes for the fruit since it is randomly placed in my code, but for the levels that would make things much easier.

Ken


Ross C(Posted 2004) [#16]
Well, Storm3, i wouldn't bother about the entity boxes for levels and pillars and such. Just use sphere>>poly collisions. Unless you need box collisions, i'd just use sphere >> poly ones. I'm sure a bit of fruit is more rounded than boxed.

You can use entitywidth, entityheight, entitydepth (i think) to get the dimentions (x,y,z) of an entity, and you could i suppose use these figure to work out the bounding box, regardless of the scale.

I always had problems with entitybox command, i guess i was too stupid to learn how to use it. :)

Sorry, my mistake, the commands are meshdepth, mesh height and mesh width. You must use scalemesh when scaling the entity, NOT scaleentity, or the results given by the height,depth, and width commands will be wrong.

As i say, i hate the entitybox command :S, but here is an example.

Use the left and right arrow keys to move the sphere.
Use the up and down arrow keys to increase the size of the box. I have include a small function that will increase the entitybox accordingly :)

Credit to AuzingLG for the resize mesh function. You MUST use scalemesh to scale the box, or the function won't work to resize the entitybox, that's what resizemesh is for :)

Graphics3D 800,600
SetBuffer BackBuffer()


Global camera=CreateCamera()
PositionEntity camera,0,0,-15

Global box=CreateCube()
PositionEntity box,-4,0,0
EntityType box,2
EntityBox box,0,-0.5,0,1,1,1


Global sphere=CreateSphere()
PositionEntity sphere,4,0,0
EntityType sphere,1
EntityColor sphere,10,40,200


Collisions 1,2,3,1

Global scale#=1


While Not KeyHit(1)



	If KeyDown(200) Then
		scale=scale+0.2
		resizeMesh(box,scale,scale,scale)
		update_bounding_box(box)
	End If
	If KeyDown(208) Then
		scale=scale-0.2
		resizeMesh(box,scale,scale,scale)
		update_bounding_box(box)
	End If


	If KeyDown(203) Then
		MoveEntity sphere,-0.1,0,0
	ElseIf KeyDown(205) Then
		MoveEntity sphere,0.1,0,0
	End If
	
	UpdateWorld
	RenderWorld
	Flip
Wend


Function update_bounding_box(entity)
	x=MeshWidth(entity)
	y=MeshHeight(entity)
	z=MeshDepth(entity)
	EntityBox box,0,-0.5,0,x/2,y/2,z/2
End Function
	
Function ResizeMesh(mesh,width#,height#,depth#)
   
   ScaleMesh mesh,1/MeshWidth#(mesh)*width#,1/MeshHeight#(mesh)*height#,(1/MeshDepth#(mesh))*depth#

End Function



StOrM3(Posted 2004) [#17]
Okay, but the level that the fruit are on, or landing on is a top open box type with walls and a floor. I need to probably load the walls and floor separately to get the collision with the floor right for the fruit, the walls should stop the player.


Ross C(Posted 2004) [#18]
Yes, but don't do box collisions for the walls. Just use sphere to poly collisions :)