Re: Anyone know anything about trigonometry?

new topic     » goto parent     » topic index » view thread      » older message » newer message

This is a multi-part message in MIME format.

------=_NextPart_000_003F_01C1371C.2C84D7C0
	charset="Windows-1252"

David,

they are not arcs. They are quite complex ballistic curves. But let's
assume we live in a complete vacuum, as some of us do, then we can
approximate them very well with parabolas. And parabolas are dead easy
to calculate, even to draw. The attached small demo is, I hope,
sufficiently commented to give you reasonable idea how to proceed.

jiri

----- Original Message -----
From: <dstanger at belco.bc.ca>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, 6 September 2001 16:57
Subject: Anyone know anything about trigonometry?


>
> Hello all,
>
> Does anyone know anything about trigonometry? I am interested in
making a
> "dueling artillery" game but cannot fathom the math needed to plot
arcs. I
> know that it has something to do with arc, tan, and cos (?) but
what?!
>
> So this is a call to all you mathematicians on the list ;)
>
> Thanks a lot,
> David S.
>
>
>

------=_NextPart_000_003F_01C1371C.2C84D7C0
Content-Type: application/octet-stream;
	name="Gun.ex"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Gun.ex"

--  gun.ex
--  jiri babor
--  jbabor at paradise.net.nz
--  6 Sep 2001

include graphics.e

constant d2r =3D PI/180           -- degrees-to-radians factor
constant g =3D 5                  -- acceleration due to gravity
object o
sequence vc                     -- video configuration
atom hspeed,vspeed,x,x0,y,y0
integer angle, color, key, speed, toggle,xmax,ymax

procedure show_header()
    text_color(BLUE)
    puts(1, "enter : toggle lines/dots\n")
    puts(1, "up    : increase angle\n")
    puts(1, "down  : decrease angle\n")
    puts(1, "right : increase speed\n")
    puts(1, "left  : decrese speed\n")
    puts(1, "c     : change trace color\n")
    puts(1, "delete: clear screen\n")
    puts(1, "space : fire\n")
    puts(1, "esc   : quit\n")


    text_color(RED)
    position(11, 1)
    if toggle then
        puts(1, "lines")
    else
        puts(1, "dots ")
    end if
    position(12, 1)
    printf(1, "angle : %2d", angle)
    position(13, 1)
    printf(1, "speed :%3d", speed)
    position(14, 1)
    printf(1, "color : %2d", color)
end procedure

procedure fire()
    hspeed =3D speed * cos(angle*d2r)     -- horizontal speed component
    vspeed =3D -speed * sin(angle*d2r)    -- vertical speed component
    x0 =3D 0                              -- initial projectile position
    y0 =3D ymax                           -- also gun position
    x =3D x0                              -- projectile hor. position
    y =3D y0                              -- projectile ver. position
    while x <=3D xmax and y <=3D ymax do
        vspeed +=3D g                     -- new vertical speed
        x +=3D hspeed                     -- new projectile position
        y +=3D vspeed
        if toggle then
            draw_line(color, {{x0, y0},{x, y}})
        else
            pixel(color, {x, y})
        end if
        x0 =3D x
        y0 =3D y
    end while
end procedure


-- initial (default) parameters:
angle =3D 60                      -- gun angle from horizontal
speed =3D 60                      -- nozzle speed
toggle =3D 1                      -- draw lines
color =3D 15                      -- BRIGHT_WHITE, initial trace color

o =3D graphics_mode(18)           -- 640x480x16
vc =3D video_config()
xmax =3D vc[5]-1
ymax =3D vc[6]-1

show_header()
ellipse(7,1,{-5,ymax-5},{5,ymax+5}) -- gun

key =3D get_key()
while key !=3D 27 do              -- escape
    if key =3D 328 then           -- up arrow
        if angle < 80 then
            angle +=3D 1
            position(12, 9)
            printf(1, "%2d", angle)
        end if
    elsif key =3D 336 then        -- down arrow
        if angle > 10 then
            angle -=3D 1
            position(12, 9)
            printf(1, "%2d", angle)
        end if
    elsif key =3D 333 then        -- right arrow
        if speed < 100 then
            speed +=3D 1
            position(13, 8)
            printf(1, "%3d", speed)
        end if
    elsif key =3D 331 then        -- left arrow
        if speed > 10 then
            speed -=3D 1
            position(13, 8)
            printf(1, "%3d", speed)
        end if
    elsif key =3D 13 then         -- enter: dots/lines toggle
        toggle =3D not toggle
        position(11, 1)
        if toggle then
            puts(1, "lines")
        else
            puts(1, "dots ")
        end if
    elsif key =3D 32 then         -- space: fire!
        fire()
    elsif key =3D 'c' then        -- change trace color
        color +=3D 1
        if color > BRIGHT_WHITE then
            color =3D GREEN
        end if
        position(13, 9)
        printf(1, "%2d", color)
    elsif key =3D 339 then        -- delete: clear screen
        clear_screen()
        show_header()
        ellipse(7,1,{-5,ymax-5},{5,ymax+5})
    end if
    key =3D get_key()
end while
o =3D graphics_mode(-1)           -- back to text mode

------=_NextPart_000_003F_01C1371C.2C84D7C0--

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu