Animated .b3d with collisions demo

BlitzMax Modules Forums/MiniB3D/Animated .b3d with collisions demo

Hi,
here is a small demo i made to test out minib3d version 0.4. I have included minib3d 0.4 in the zip file.

feel free to use the included media files (the .b3d, ogg and textures were all created by me) without restriction.

use WASD to move the robot around and arrow keys to adjust the camera.

http://www.bmaxbook.com/RobotAnimtest.zip




edit: fixed Octree command per simonh's comment

Love the graffiti :)

Your octree settings are a little excessive for the size of the mesh used. Use values of 0,3 for a big speed increase.

very nice :)

this demo had shown me a bug with my extended Version which could now be fixed. I have forgotten to change the the b3d loader to load the brushes in a different way to support the shader brush.

thanks. fixed the Octree and uploaded new zip (huge speed boost on my PC!). also made flip = 0 so FPS can be measured.

some notes:
while i was making this demo I came across a few things. I won't call them bugs because I realize that you have not finalized the anim commands so please ignore this if it sounds redundant.

1. animate(mesh) speed is taking an int (needs to be a float)
2. animtime is not wrapping on the negative side. if you un-rem the text commands and 'walk' backwards you will see this in action.
3. I was trying to play an ogg when the animtime=floorstrike but i haven't been able to get my head around the sound commands (channel?/sound?/blah) but a made a AAA .ogg sound effect in audacity :) (that is me banging on my PC desk with a stapler)
4. The Robot is 1738 polys (876 verts) with 30 frames of animation. It is textured with a single 256x256 .jpg (i kept all of the images at 256x256 to make sure this works on older vidcards)
5. the level is just a single mesh with 2 surfaces(brick & floor) + a light map ( i drew the graffiti on the lightmap).


overall, minib3D has been rock-solid during all of this. no crashes and no problems. very impressive! you guys are doing a fantastic job on this and I am very grateful.

Great demo!

For the sound insert
Local mySound:TSound = LoadSound ("media/clank.ogg")
Local channel:TChannel =PlaySound (mySound)

but I wouldn't know how to determine when the foot touches the ground?

Thanks Dirk.
It was easy to figure out when the foot touches the ground (if you unrem the 'text' lines at the bottom of the code and watch the frames you can see the foot strikes)

my problem was playing the sound once per strike and 'not playing' if the foot rests on that frame. i did not want to mess with that too much because I am working on transitioning to an idle pose when the figure stops.

anyway. good info!

oh, I see. Then it's something like this:

before the mainloop:
Local mySound:TSound = LoadSound ("media/clank.ogg")
Local oldclongstate:Int = 0
Local clongstate:Int = 0


before the Flip:
clongstate = Int(AnimTime(robot)/14)

If oldclongstate <> clongstate
  Local channel:TChannel =PlaySound (mySound)
  oldclongstate = clongstate
EndIf


very nice! I will play with this and update the demo (after dinner & a movie :) )

btw - what application did you use to create this great scenery? I esp. saw that the grafitti is drawn into the lightmap, cool idea!

funny thing is that it took WAY longer to create the Robot (bones, animations, etc) but the scenery took about 20 mins. I used Maplet, 3ds, Ultimate Unwrap and pshop, although I probably could have done the whole thing in Maplet and just have been done with it.



I have updated the demo with a smooth 3rd person camera (requested in another thread) but here is the code so you don't have to download the whole zip file if you already have it.

Import "MiniB3D.bmx"

Strict

Local width=1024,height=768,depth=32,mode=0 ; Graphics3D width,height,depth,mode

Local cam:TCamera=CreateCamera()
CameraRange cam,.5,1500
Local camdistance:Float = 600
Local camera_mode:Int
Local camera_mode_String:String
PositionEntity cam,0,10,-100

AmbientLight 200,200,200

Local Level:TMesh=LoadMesh("media/gamelevel.b3d")
CreateOctree(level,0,3)					' create mesh octree - makes collision detection faster (MiniB3D only)

Local robot:TMesh=LoadAnimMesh("media/robotwalk.b3d")
ScaleEntity robot,0.025,0.025,0.025

Global robot_pivot:Tpivot =CreatePivot(robot) 
MoveEntity robot_pivot,0,0,camdistance		' move the pivot back a little  For follow effect

EntityType robot,1						' set ROBOT entity type to 1

Local robot_radius:Float =7.25				' set ROBOT radius as it's the source collision entity
EntityRadius robot,robot_radius
Local collsphere:Tmesh = CreateSphere(8,robot)
ScaleEntity Collsphere,robot_radius,robot_radius,robot_radius
EntityType Level,2						' set mesh entity Type To 2
Collisions 1,2,4,2							'  enable colliisons between entity type 1 and 2, with reponse 4

' used by camera code
Local mxs#=0 	;	Local mys#=0	;	Local move#=0.5
MouseXSpeed() 	;	MouseYSpeed() ' initial flush of mouse values

' used by fps code
Local old_ms=MilliSecs()	;	Local renders	 	;	Local fps

' anim stuff
Local frame:Float	,  speed:Float , yspeed:Float


' MAIN LOOP BEGIN
While Not KeyDown(KEY_ESCAPE)		

	If KeyHit(KEY_ENTER) Then DebugStop

	If KeyHit(KEY_SPACE) Then camera_mode = 1 - camera_mode
		
		If camera_mode = 0
			camera_mode_String$ = "mouse look + Arrow keys"
			mxs#=mxs#+(MouseXSpeed()/5.0)
			mys#=mys#+(MouseYSpeed()/5.0)
		
			MoveMouse width/2,height/2
			MouseXSpeed() ' flush
			MouseYSpeed() ' flush
		
			RotateEntity cam,mys#,-mxs#,0
			'PointEntity(cam,robot)
			
			If KeyDown(KEY_UP)=True Then MoveEntity cam,0,0,move#
			If KeyDown(KEY_DOWN)=True Then MoveEntity cam,0,0,-move#
		
		
			If KeyDown(KEY_LEFT)=True Then MoveEntity cam,-move#,0,0 ' move camera left
			If KeyDown(KEY_RIGHT)=True Then MoveEntity cam,move#,0,0 ' move camera right
		
		Else
				camera_mode_String$ = "smoothcam"

				smoothcam(cam,robot_pivot,robot,50,15)
		EndIf
	
	
	If KeyDown(KEY_W)  Then speed:+.009

	If KeyDown(KEY_S) Then speed:-.009


	If KeyDown(KEY_A) Then TurnEntity robot,0,1,0
	If KeyDown(KEY_D) Then TurnEntity robot,0,-1,0

	speed:* 0.99
	yspeed:-0.1
	If yspeed<-3 Then yspeed = 0
	
	MoveEntity robot,0,yspeed,-speed
	
	' manually roll the animation
	frame:+(speed)
	If frame>30 Then frame = 0
	SetAnimTime(robot,frame)
	
	UpdateWorld
	RenderWorld
	renders=renders+1
	' calculate fps
	If MilliSecs()-old_ms>=1000
		old_ms=MilliSecs()
		fps=renders
		renders=0
	EndIf

		Text 0,0,"FPS: "+String(fps)
		text 0,20,"SPACE to change Camera Mode"
		text 0,40," WASD to move ROBOT"
		text 0,60,camera_mode_String$
	Flip 
	
Wend
' MAIN LOOP END

End

Function smoothcam(camera:Tcamera,pivot:Tpivot,target:Tentity,camspeed:Float,height:Float)


	Local curx#=EntityX(camera)
	Local curz#=EntityZ(camera)
	Local cury#=EntityY(target) + height
	Local destx#=EntityX(pivot,True)
	Local destz#=EntityZ(pivot,True)
	
	
	curx#=curx#+((destx#-curx#)/camspeed)
	curz#=curz#+((destz#-curz#)/camspeed)
	

	PositionEntity camera,curx#,cury#,curz#

	PointEntity camera,target
End Function




.