OK, I wrote a tutorial. Who thinks I should make my own separate thread about this?
So, here is the tutorial:
1) Commands and Terms
First of all, you need to know the basic terms and commands for animating your objects in these categories:
a)Making objects
b)Making meshes
c)Adding limbs
d)Rotating and Offsetting limbs
e)Setting keyframes
f)Interpolation
a)Making objects
There is not a lot to explain here. This is how you make objects. In the code snippet, I make them all the size of 10:
rem make some objects
make object plain 1,10,10
make object cube 2,10
make object box 3,10,10,10
make object cylinder 4,10
make object cone 5,10
make object sphere 6,10
make object triangle 7,0,0,0,10,0,0,0,10,0
And here is the whole program:
rem setup screen
set display mode 1024,768,32
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem dimensions
dim text$(6)
text$(0)="plain"
text$(1)="cube"
text$(2)="box"
text$(3)="cylinder"
text$(4)="cone"
text$(5)="sphere"
text$(6)="triangle"
rem make texture
gosub _generate_image
rem make some objects
make object plain 1,10,10
make object cube 2,10
make object box 3,10,10,10
make object cylinder 4,10
make object cone 5,10
make object sphere 6,10
make object triangle 7,0,0,0,10,0,0,0,10,0
rem position the objects
for t=1 to 7
position object t,t*12,0,0
texture object t,1
scale object texture t,2,2
next t
rem position camera
position camera 42,40,-60
point camera 42,0,0
rem main loop
do
rem text
for t=1 to 7
x=object screen x(t)
y=object screen y(t)-100
center text x,y,text$(t-1)
yrotate object t,wrapvalue(object angle y(t)+2)
next t
rem end of loop
sync
loop
rem end
end
_generate_image:
create bitmap 1,128,128
for t=1 to 1000
r=rnd(100)+100
ink rgb(r,r,r),0
circle rnd(128),rnd(128),rnd(128)
next t
ink rgb(100,100,100),0
line 0,0,127,0
line 127,0,127,127
line 127,127,0,127
line 0,127,0,0
ink rgb(180,180,180),0
line 1,1,126,1
line 126,1,126,126
line 126,126,1,126
line 1,126,1,1
fade bitmap 1,100
get image 1,0,0,128,128
delete bitmap 1
return
b)Making meshes
In this snippet, I will display all of the objects again, but I will make the objects using meshes:
To make a mesh, you make an object first:
now we get the object, and turn it into a mesh:
Syntax:
Make Mesh From Object <mesh number>
,<object number>
So now the object is stored in a mesh, that you can use later for re-creating the object.
make mesh from object 1,1
delete object 1
And to create the object again:
Syntax:
Make Object <object to create from the mesh>
,<mesh to use>
,image to texture object with>
So lets do that with our program:
rem setup screen
set display mode 1024,768,32
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem dimensions
dim text$(6)
text$(0)="plain"
text$(1)="cube"
text$(2)="box"
text$(3)="cylinder"
text$(4)="cone"
text$(5)="sphere"
text$(6)="triangle"
rem make texture
gosub _generate_image
rem make some objects
make object plain 1,10,10
make object cube 2,10
make object box 3,10,10,10
make object cylinder 4,10
make object cone 5,10
make object sphere 6,10
make object triangle 7,0,0,0,10,0,0,0,10,0
rem turn the objects into meshes
for t=1 to 7
make mesh from object t,t
delete object t
next t
rem now make the objects from the meshes
for t=1 to 7
make object t,t,0
delete mesh t
next t
rem position the objects
for t=1 to 7
position object t,t*12,0,0
texture object t,1
scale object texture t,2,2
next t
rem position camera
position camera 42,40,-60
point camera 42,0,0
rem main loop
do
rem text
for t=1 to 7
x=object screen x(t)
y=object screen y(t)-100
center text x,y,text$(t-1)
yrotate object t,wrapvalue(object angle y(t)+2)
next t
rem end of loop
sync
loop
rem end
end
_generate_image:
create bitmap 1,128,128
for t=1 to 1000
r=rnd(100)+100
ink rgb(r,r,r),0
circle rnd(128),rnd(128),rnd(128)
next t
ink rgb(100,100,100),0
line 0,0,127,0
line 127,0,127,127
line 127,127,0,127
line 0,127,0,0
ink rgb(180,180,180),0
line 1,1,126,1
line 126,1,126,126
line 126,126,1,126
line 1,126,1,1
fade bitmap 1,100
get image 1,0,0,128,128
delete bitmap 1
return
c) Adding Limbs
Up until now, we have made 7 different objects and positioned them. Now lets say, you want those 7 objects to only be one object. To do this, you have to make meshes from those objects, and create limbs from the meshes.
So, make an object:
make a mesh from the object and delete the object (we wont need the object again)
make mesh from object 1,1
delete object 1
and now we get the mesh and add a limb to an object. To add a limb to an object, we need to make an object first. This object should be invisible(make the size 0):
Now we can add the limb to the "invisible object":
Syntax:
Add Limb <object to add limb>
,<limb number>
,<mesh to make limb from>
So lets do this with our program:
rem setup screen
set display mode 1024,768,32
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem dimensions
dim text$(6)
text$(0)="plain"
text$(1)="cube"
text$(2)="box"
text$(3)="cylinder"
text$(4)="cone"
text$(5)="sphere"
text$(6)="triangle"
rem make texture
gosub _generate_image
rem make some objects
make object plain 1,10,10
make object cube 2,10
make object box 3,10,10,10
make object cylinder 4,10
make object cone 5,10
make object sphere 6,10
make object triangle 7,0,0,0,10,0,0,0,10,0
rem position the objects
for t=1 to 7
position object t,t*12,0,0
texture object t,1
scale object texture t,2,2
next t
rem turn the objects into meshes
for t=1 to 7
make mesh from object t,t
delete object t
next t
rem now create limbs from the meshes
make object plain 1,0,0
for t=1 to 7
add limb 1,t,t
delete mesh t
next t
rem texture the object
texture object 1,1
scale object texture 1,2,2
rem position camera
position camera 0,40,-90
point camera 0,0,0
rem main loop
do
rem rotate
yrotate object 1,wrapvalue(object angle y(1)+2)
rem end of loop
sync
loop
rem end
end
_generate_image:
create bitmap 1,128,128
for t=1 to 1000
r=rnd(100)+100
ink rgb(r,r,r),0
circle rnd(128),rnd(128),rnd(128)
next t
ink rgb(100,100,100),0
line 0,0,127,0
line 127,0,127,127
line 127,127,0,127
line 0,127,0,0
ink rgb(180,180,180),0
line 1,1,126,1
line 126,1,126,126
line 126,126,1,126
line 1,126,1,1
fade bitmap 1,100
get image 1,0,0,128,128
delete bitmap 1
return
d) Rotating and offsetting limbs
The object now has 7 limbs, and the object rotates around the Y axis. I don`t like the way it is shifted far to the left, so we can now offset the limbs to shift the limbs to the center:
Syntax:
Offset Limb <object number>
,<limb number>
,<X offset>
,<Y offset>
,<Z offset>
When you offset limbs, the x,y and z coordinates are not actual 3D coordinates. That means that you cannot position a limb in 3D space with this command. What it does, is it moves it away from it`s original position by the amount given. So if I say "offset limb 1,1,0,0,0", the limb 1 from the object 1 will not position at 0,0,0, it will position at where the limb was originally positioned. (Tell me if you don`t get it)
So, to shift all of the 7 limbs left by 42 steps, you would do:
for t=1 to 7
offset limb 1,t,-42,0,0
next t
To rotate limbs, you use the same:
Syntax:
Rotate Limb <object number>
,<limb number>
,<angle X>
,<angle Y>
,<angle Z>
Lets rotate the limbs randomly:
for t=1 to 7
rotate limb 1,t,rnd(360),rnd(360),rnd(360)
next t
So, lets add that to our program:
rem setup screen
set display mode 1024,768,32
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem dimensions
dim text$(6)
text$(0)="plain"
text$(1)="cube"
text$(2)="box"
text$(3)="cylinder"
text$(4)="cone"
text$(5)="sphere"
text$(6)="triangle"
rem make texture
gosub _generate_image
rem make some objects
make object plain 1,10,10
make object cube 2,10
make object box 3,10,10,10
make object cylinder 4,10
make object cone 5,10
make object sphere 6,10
make object triangle 7,0,0,0,10,0,0,0,10,0
rem position the objects
for t=1 to 7
position object t,t*12,0,0
texture object t,1
scale object texture t,2,2
next t
rem turn the objects into meshes
for t=1 to 7
make mesh from object t,t
delete object t
next t
rem now create limbs from the meshes
make object plain 1,0,0
for t=1 to 7
add limb 1,t,t
delete mesh t
next t
rem offset the limbs 42 steps to the left
for t=1 to 7
offset limb 1,t,-42,0,0
next t
rem randomly rotate the limbs
for t=1 to 7
rotate limb 1,t,rnd(360),rnd(360),rnd(360)
next t
rem texture the object
texture object 1,1
scale object texture 1,2,2
rem position camera
position camera 0,40,-90
point camera 0,0,0
rem main loop
do
rem rotate
yrotate object 1,wrapvalue(object angle y(1)+2)
rem end of loop
sync
loop
rem end
end
_generate_image:
create bitmap 1,128,128
for t=1 to 1000
r=rnd(100)+100
ink rgb(r,r,r),0
circle rnd(128),rnd(128),rnd(128)
next t
ink rgb(100,100,100),0
line 0,0,127,0
line 127,0,127,127
line 127,127,0,127
line 0,127,0,0
ink rgb(180,180,180),0
line 1,1,126,1
line 126,1,126,126
line 126,126,1,126
line 1,126,1,1
fade bitmap 1,100
get image 1,0,0,128,128
delete bitmap 1
return
As you can see, the limbs are not rotated around their own axis, but around the core object(the "invisible object")
e) Setting Keyframes
This is the part that we animate the object.
Every time you rotate or offset a limb, you can set a keyframe, which you can later set with "set object frame". Lets say you rotate the limbs to 0,0,0, and set a keyframe to 0. Then you rotate the limbs to 180,0,0 and set a keyframe to 1.
If you then say "set object frame" and set the object frame to 0, the limbs will be rotated to 0, and if you set the object frame to 1, the limbs will be rotated to 180,0,0.
You can use this technique for opening doors or moving platforms up and down. Just by changing the frame of the object in the main loop after setting the keyframes.
So lets set a keyframe when the limbs are rotated to 0,0,0, and when they are rotated randomly:
rem setup screen
set display mode 1024,768,32
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem dimensions
dim text$(6)
text$(0)="plain"
text$(1)="cube"
text$(2)="box"
text$(3)="cylinder"
text$(4)="cone"
text$(5)="sphere"
text$(6)="triangle"
rem make texture
gosub _generate_image
rem make some objects
make object plain 1,10,10
make object cube 2,10
make object box 3,10,10,10
make object cylinder 4,10
make object cone 5,10
make object sphere 6,10
make object triangle 7,0,0,0,10,0,0,0,10,0
rem position the objects
for t=1 to 7
position object t,t*12,0,0
texture object t,1
scale object texture t,2,2
next t
rem turn the objects into meshes
for t=1 to 7
make mesh from object t,t
delete object t
next t
rem now create limbs from the meshes
make object plain 1,0,0
for t=1 to 7
add limb 1,t,t
delete mesh t
next t
rem offset the limbs 42 steps to the left
for t=1 to 7
offset limb 1,t,-42,0,0
next t
rem set a keyframe
set object keyframe 1,0
rem randomly rotate the limbs
for t=1 to 7
rotate limb 1,t,rnd(360),rnd(360),rnd(360)
next t
rem set a keyframe
set object keyframe 1,1
rem texture the object
texture object 1,1
scale object texture 1,2,2
rem position camera
position camera 0,40,-90
point camera 0,0,0
rem main loop
play object 1
sleep 1000
do
rem change the frame
center text 512,10,"Press the left mouse button to change frames"
if mouseclick()=1 and pushed=0
inc frame:if frame>1 then frame=0
pushed=1
set object frame 1,frame
endif
if mouseclick()=0 and pushed=1 then pushed=0
rem rotate
yrotate object 1,wrapvalue(object angle y(1)+2)
rem end of loop
sync
loop
rem end
end
_generate_image:
create bitmap 1,128,128
for t=1 to 1000
r=rnd(100)+100
ink rgb(r,r,r),0
circle rnd(128),rnd(128),rnd(128)
next t
ink rgb(100,100,100),0
line 0,0,127,0
line 127,0,127,127
line 127,127,0,127
line 0,127,0,0
ink rgb(180,180,180),0
line 1,1,126,1
line 126,1,126,126
line 126,126,1,126
line 1,126,1,1
fade bitmap 1,100
get image 1,0,0,128,128
delete bitmap 1
return
f) Interpolation
This is a wonder of programming. Without this function, you would have to set each frame of every change you make.
Interpolation will guess where the limbs would be at frames between the keyframes. So, if you set a keyframe to 0 when the limbs are rotated at 0,0,0, and set a keyframe to 20 when the limbs are rotated at 0,60,0, and you set the object frame to 10, where do you think the limb will be rotated?
At 0,0,0 or at 0,60,0? The answer is 0,30,0. If I set the object frame to 5, it would be at 0,15,0. So, interpolation guesses where the limb will be between the keyframes.
So lets be simple. I will rotate the limbs to 0,0,0, set a keyframe to 0, the rotate the limbs randomly and set a keyframe to 50.
After that, you can use "play object" or "loop object" and it will play all of the frames. So, here is the program:
rem setup screen
set display mode 1024,768,32
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem dimensions
dim text$(6)
text$(0)="plain"
text$(1)="cube"
text$(2)="box"
text$(3)="cylinder"
text$(4)="cone"
text$(5)="sphere"
text$(6)="triangle"
rem make texture
gosub _generate_image
rem make some objects
make object plain 1,10,10
make object cube 2,10
make object box 3,10,10,10
make object cylinder 4,10
make object cone 5,10
make object sphere 6,10
make object triangle 7,0,0,0,10,0,0,0,10,0
rem position the objects
for t=1 to 7
position object t,t*12,0,0
texture object t,1
scale object texture t,2,2
next t
rem turn the objects into meshes
for t=1 to 7
make mesh from object t,t
delete object t
next t
rem now create limbs from the meshes
make object plain 1,0,0
for t=1 to 7
add limb 1,t,t
delete mesh t
next t
rem offset the limbs 42 steps to the left
for t=1 to 7
offset limb 1,t,-42,0,0
next t
rem set a keyframe
set object keyframe 1,0
rem randomly rotate the limbs
for t=1 to 7
rotate limb 1,t,rnd(360),rnd(360),rnd(360)
next t
rem set a keyframe
set object keyframe 1,50
rem texture the object
texture object 1,1
scale object texture 1,2,2
rem position camera
position camera 0,40,-90
point camera 0,0,0
rem main loop
do
rem play the object
center text 512,10,"Press the left mouse button to play the object"
text 0,20,"Current Object Frame : "+str$(object frame(1))
if mouseclick()=1 and pushed=0
play object 1
endif
if mouseclick()=0 and pushed=1 then pushed=0
rem end of loop
sync
loop
rem end
end
_generate_image:
create bitmap 1,128,128
for t=1 to 1000
r=rnd(100)+100
ink rgb(r,r,r),0
circle rnd(128),rnd(128),rnd(128)
next t
ink rgb(100,100,100),0
line 0,0,127,0
line 127,0,127,127
line 127,127,0,127
line 0,127,0,0
ink rgb(180,180,180),0
line 1,1,126,1
line 126,1,126,126
line 126,126,1,126
line 1,126,1,1
fade bitmap 1,100
get image 1,0,0,128,128
delete bitmap 1
return
You can change the speed of the object with "set object speed".
When you get a little more advanced, you can use sin() and cos() to smooth your objects animation, but work on this for now.
Hope this tutorial helps!
TheComet
Peachy, and the Chaos of the Gems
