Animated Sprites

Blitz3D Forums/Blitz3D Beginners Area/Animated Sprites

earok(Posted 2005) [#1]
Hi there,

Is it possible to do animated sprites in a 3D world in Blitz3D, for instance, like the guards from Wolfenstein 3D or the monsters from DooM? If so, then how?


Many thanks,
--
Erik Hogan


Matty(Posted 2005) [#2]
Yes.

In my "never to be finished" game that I am no longer working on I used this technique. Download is available here (should have source code too):

http://home.swiftdsl.com.au/~gezeder/lloyd/GBS_Update.zip

If you were using blitz3d sprites then you would do the following:

Create an animated texture containing 64 frames - 8 across and 8 down each of size 32 pixels by 32 pixels (256x256 sized texture). Each of these frames contains a rendered image of your 'man' from a different direction and pose.

Prior to calling renderworld loop through all of the sprites and set their texture frame based on what direction they are facing and what direction the camera is facing. In my game I used 4 frames for walking, 3 frames for attacking and 1 frame for dying (8 in total) with 8 directions (45 degree angle rotations around y axis) to give 64 frames in total.


Erroneouss(Posted 2005) [#3]
Cool! Perfect for my "Duck Nukem 3D" game! Thanks!


earok(Posted 2005) [#4]
Whoa, that was pretty neat Matty. I havent seen much done in Blitz3D that could match the sight of hundreds of French and British soldiers fighting to the death in Waterloo. Its a pity that you're not going to finish it but I bet you're making a much better game now. Um, you couldent possibly name which source code file has the sprite handler routine? Theres heaps of them and I have no idea where to start sorry :S


Heh.. I guess I wasnt the only one who decided to make a game that spoofs an old First Person Shooter.


Many thanks!
--
Erik Hogan


Matty(Posted 2005) [#5]
earok - the source code file "update3dentities.bb" has this bit in it:

The lines which work out a value for variable "NewDirn" establish which row (1-8) of the texture to use based on the camera orientation relative to the billboard model.

The line "correctframe=..." is where I set the appropriate texture frame to use.

The function "animatequad" uses my old single surface quad system to set the uv coordinates of the sprite based on the value of "correctframe". I wouldn't worry too much about the "animatequad" function - it is in the "Latestquadfuncs.bb" file.

If you are using blitz sprites then the only calculations you need are upto the point where 'correctframe' is calculated and then you can pass this directly to the entitytexture command as the 'frame' parameter.


In update3dentities.bb I calculate the value for "camdirn" and use that further down as you will see

CamAngle=EntityYaw(Camera,True) Mod 360
If CamAngle<0 Then CamAngle=CamAngle+360
CamDirn=(315-CamAngle)/45



	If Unit(k)\Billboard Then 
				If Unit(k)\QuadID<>-1 Then 
				;Animate the Quad appropriately..
					NewDirn=7+Unit(k)\Direction-CamDirn
					If NewDirn>8 Then NewDirn=NewDirn-8
					If NewDirn<0 Then NewDirn=NewDirn+8
					If NewDirn=0 Then NewDirn=8
					CorrectFrame=(Unit(k)\CurrentFrame-1)+(NewDirn-1)*8
				
				;If InCameraView(Unit(k)\X,Unit(k)\Y,Unit(k)\Z,Camera) And if Unit(k)\Billboard=1 Then AnimateQuad(Unit(k)\QuadID,1,1,8,8,CorrectFrame)
					If Combatant(Unit(k)\Category)\Animated Then AnimateQuad(Unit(k)\QuadID,1,1,8,8,CorrectFrame)
				;Billboard will be set to 1 for animated sprites, and to 2 for static objects like barbed wire.
				;CurrentFrame-1 as the Calculate Action uses a system which begins at 1 and ends at 
				;the maximum number of frames, while the quad functions have 0 as the first frame.
				;
				;
				
				
				;Position quad and face the camera....
					InitialQuadPosition(Unit(k)\QuadID,Unit(k)\X,Unit(k)\Y+OffsetY,Unit(k)\Z,0)
				
				
					PointAndCentre(Unit(k)\QuadID,EntityYaw(Camera,True))
					PositionQuadCentred(Unit(k)\QuadId)
		
	



IPete2(Posted 2005) [#6]
Your could also chgeck out "Sprite Candy" which has some awesome features.

IPete2.


Morbius(Posted 2011) [#7]
I know it's a longshot, but anyone have GBS_Update.zip?

I'm interested in the code that determines which direction animation to use.

Thanks


jfk EO-11110(Posted 2011) [#8]
Matty's still around, maybe he can help you directly. Or try it in general help.

Last edited 2011


Matty(Posted 2011) [#9]
Sorry Morbius - I don't think I have easy access to that code anymore (if I do have it it's on a computer that hasn't been used in years which I don't have much way of getting stuff off from..)

However - that doesn't mean I cannot help.

It has been a while since I've done this but what you should play around with this the following (assuming you want sprites for character models like in Shogun Total War or the older raycasting Doom / Wolfenstein games)...

Calculate the angle the sprite *character* is facing between 0 and 360 degrees. Then divide it by 45 to get a value between 0 and 7...

direction=(angle / 45) mod 8 ; or something like that.

then you need to do the same with the camera angle (yaw) - get a value between 0 and 7.

Now this is where you need to play around with it - I cannot remember the exact method, - it can be worked out but I am not able to do that right now -

Subtract the direction (0-7) from the camera direction (0-7) and then convert the resulting value into a number from 0-7.

Assuming your sprites are laid out in 8 rows, with each row being a particular direciton, you can then use the resulting figure from the calculation above to determine which row to draw from.

Hope that is in someway helpful.


Morbius(Posted 2011) [#10]
Matty,

Thanks very much. That is helpful. I am indeed working on a Wolfenstein-ish game. I'm going to try just four directions first.