forums

TNT Basic Forums > Programming Q&A
example
< Last Thread     Next Thread >
Author
Thread        Post A Reply

03-23-2003 19:26

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

here is the code for which i needed arc cos:


graphics mode hardware 800, 600
load images 128
set framerate max
'draw tracking off

int x
int y
int d
int r
int da
int db
int dc
float cosr

da = 300

set sprite color 0, make color (255, 0, 255)
set pen transparency 70
line 400, 300 to 400, 0


repeat

x = mouse x
y = mouse y
line 400, 300 to x, y
db = sqrt ((400 - x)^2 + (300 - y)^2)
dc = sqrt ((400 - x)^2 + (0 - y)^2)
cosr = ((dc^2 - da^2 - db^2) / (-2 * da * db))
r = round(invcos(cosr))
if mouse x = 400 then r = r
if mouse x <= 400 then d = 180 - r
r = r + d
if r < 0 then d = 180 + r
r = r + d
sprite 0, 400, 300, 0
set sprite rotation 0, r
draw frame

until true = pressed (12)



so now i have a problem when the rotation is at 180 degrees. i wont go to the trouble of explaining the code, but i'd love it if someone could try it out and offer me an explanation for its strangeness. just put in a sprite for image 128. the lines that appear will just be imaginary, but i've drawn them here so you can see what's happening.

all this code is just a work around for the macs inability to wrap the mouse around. it rotates the sprite so that it always faces the mouse coordinates.


All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.