kRx,
It is standard for me to use cos and sin to move my character with a given angle.
REM << turn player character
if rightkey() = 1 then inc angle#
if leftkey() = 1 then dec angle#
REM << move player character foward
if upkey() = 1
x# = x# + (sin(angle#) * 2)
y# = y# + (cos(angle#) * 2)
endif
In my experiments, which are usually done with basic 2d commands, for quickness, I draw with cos and sin. For example, in any experiment that contains a character holding a gun, I use cos and sin to draw an offsetted line from the character, as the barrel of the gun.
REM << draw character to screen
circle px#,py#,10
REM << player gun side-offset
gunx1# = px# + (sin(wrapvalue(angle# + 90)) * 11)
guny1# = py# + (cos(wrapvalue(angle# + 90)) * 11)
line gunx1#,guny1#,gunx1# + (sin(angle#) * 12),guny1# + (cos(angle#) * 12)
I've also used them, in the same manner as above, to create the
physics of a bouncing ball, by changing the rate of change of 'angle'. The snippet below is a fully runnable program.
set display mode 800,600,32
sync on
sync rate 60
`make textures
ink rgb(255,255,255),0
for t = 1 to 13 step 4
line 1,t,13,t
next t
get image 1,0,0,13,13
cls
`make objects
make object sphere 1,5
texture object 1,1
make object plain 2,500,10
texture object 2,1
scale object texture 2,0.10,0.50
xrotate object 2,90
xrotate camera 15
x# = 230
y# = 2.5
angle# = 135
anglechangerate# = 0.70
direction$ = "left"
speed# = 1
quitbounce = 0
repeat
`reset program upon press of space bar
if spacekey() = 1
x# = 230
y# = 2.5
angle# = 135
anglechangerate# = 0.70
speed# = 1
direction$ = "left"
quitbounce = 0
endif
`if ball collides with ground
if y# < 2.5
`if ball's bounces are on very short intervals;the rate of the change in direction
if anglechangerate# > 14
`make ball stop bouncing
quitbounce = 1
`reposition ball to above surface
y# = 2.5
`reset its angle to move in direction it is
if direction$ = "left" then angle# = 180
`if ball's bounces are on long intervals
else
lastangle# = angle#
`reset ball positionto above surface
y# = 2.5
`reset angle to opposite direction
angle# = wrapvalue(angle# - 90)
`make the ball's bounce a bit shorter
inc anglechangerate#,0.70
endif
endif
`if ball is not able to bounce, and its moving speed is greater than 0, then decrement its moving speed
if quitbounce = 1 and speed# > 0 then dec speed#,0.005
`if speed is slower than 0.01 units per loop then stop ball
if quitbounce = 1 and speed# < 0.01 then speed# = 0
`if ball is able to bounce then increment vector angle
if quitbounce = 0 then angle# = wrapvalue(angle# + anglechangerate#)
`make ball rotate;decrement rotation speed with speed#;ball will graduallyt stop rotating
rotangle# = wrapvalue(rotangle# + (5 * speed#))
`get new coordinates for ball
x# = x# + cos(angle#) * speed#
y# = y# + sin(angle#) * speed#
position object 1,x#,y#,0
zrotate object 1,rotangle#
position camera x#,20,-50
text 0,0,"ball's angle of direction:" + str$(angle#)
text 0,15,"ball's angle of direction upon last collision:" + str$(lastangle#)
text 0,30,"rate of change in angle of direction:" + str$(anglechangerate#)
text 0,45,"ball's current angle of rotation:" + str$(rotangle#)
center text 400,580,"press space bar to reset ball"
sync
until mouseclick() = 1
end
I have used them in my experiments on
raycasting, which ruled very well results.
REM << get bullet's position upon next frame sync
newx# = curx# + (cos(bulletangle#) * bulletspeed#)
newy# = cury# + (cos(bulletangle#) * bulletspeed#)
REM << get distance, for FOR NEXT loop, from bullet's current position to bullet's position upon next frame sync
distance# = sqrt((curx# - newx#)^2 + cury# - newy#)^2)
REM << throw a ray in between bullet's current and new location and check if it will pass through any object
for t = 2 to distance#
checkx# = curx# + (cos(bulletangle#) * t)
checky# = cury# + (sin(bulletangle#) * t)
REM << run a simple collision routine to check if bullet coords are within any object
collision = checkcollision(checkx#,checky#)
REM << collision = 0 if no object was hit, else the object # of the object hit is returned
if collision > 0 then exit
next t
...
If you notice the showcase section of thegamecreators homepage, you will see a program, which I believe is called
Chaos. It displays many 3d spheres all in one clean mess. It's nice.
My knowledge of cos and sin is very, very limited. However, these are a couple of great examples of their abilities. Though, much more complex tasks are doable with them.

+NanoBrain+