Posted: Wed Feb 04, 2004 4:23 pm Post subject: (No subject)
this is great! excellent work thoughtful
Sponsor Sponsor
gamer
Posted: Thu Apr 08, 2004 2:39 pm Post subject: (No subject)
helo thoughtful btw GREAT JOB on this pool program, u see im kind of new to program so my question is, do you think u can explain to me how the collision part of the program works?? i understand the fact that u applied trig but how exactly did you do it?
gamer
Posted: Sat Apr 10, 2004 6:21 pm Post subject: (No subject)
heloo??
thoughtful can ya reply?
or anyone else who knows please tell me, i reli gota understand
thnx
gamer
Posted: Mon Apr 12, 2004 3:52 pm Post subject: (No subject)
still no reply??? omg
Paul
Posted: Mon Apr 12, 2004 3:55 pm Post subject: (No subject)
Thoughtful is not on Compsci very often, and don't triple post lol, Asian Sensation would be angry at you. Im sure whenever he gets on, he'll try and reply. You could always send him a PM.
Tony
Posted: Mon Apr 12, 2004 3:59 pm Post subject: (No subject)
you find the angle
you break it up into vector components (x and y)
you find total energy transfer from the collision
you use vector components as ratios to redestribute the energy after collision.
Posted: Mon Apr 12, 2004 4:14 pm Post subject: (No subject)
thnx
evildaddy911
Posted: Sun Oct 16, 2011 1:35 pm Post subject: RE:Tutorial: Basic POOL and realistic collision
i dont have gr11 math till next semester, can you explain what you mean by vector components?
Sponsor Sponsor
Raknarg
Posted: Wed Oct 19, 2011 3:33 pm Post subject: RE:Tutorial: Basic POOL and realistic collision
It's actually physics... lets say you have a line. This line goes up by 3 and across by 4. Those woule be the x and y vector components: The change in x and the change in y.
Correect me if I'm wrong.
evildaddy911
Posted: Wed Oct 19, 2011 3:47 pm Post subject: RE:Tutorial: Basic POOL and realistic collision
so its like finding slope, but not actually finding the slope, cuz slope is change in y divided by change in x, but you dont do the dividing
Raknarg
Posted: Wed Oct 19, 2011 3:53 pm Post subject: RE:Tutorial: Basic POOL and realistic collision
Its basically trigonometry. Usually when you're working with vectors, you are given a bunch of distances with directions (ex. 35m[E25oS], or 25 meters, East 25 degrees to the South) and from that you calculate the overall displacement and the overall angle (compared from your starting point to your finishing point).
Posted: Thu Oct 20, 2011 3:29 pm Post subject: Re: Tutorial: Basic POOL and realistic collision
okay, so the vectors are really just horizontal/vertical distances.... and i puzzled out a quick screensaver-like program...
im not sure what you mean by displacement, but i think i could figure out the angle...
anyways, voila:
Turing:
var x, y, xv, yv :int var change_time :int:=10000 var last_change :int:= -change_time
x := Rand.Int (10, maxx - 10)
y := Rand.Int (10, maxy - 10)
xv := Rand.Int ((-5),5)
yv := Rand.Int ((-5),5) loop var now :=Time.Elapsed if now - last_change >= change_time then
xv := Rand.Int ((-5),5)
yv := Rand.Int ((-5),5)
last_change := now
endif drawfilloval(x, y, 10, 10, white)
x := xv + x
y := y + yv
if x <= 10or x >= maxx - 10then
xv := xv *(-1) endif if y >= maxy - 10or y <= 10then
yv := yv *(-1) endif
const xPos :=350 const yPos :=350 var x, y, b :int:=0% variables for the Mouse.Where var t :real% Theta, or the angle var bltx, blty, bltvx, bltvy :real:=0% the bullet positions, and the amount the x and y changes var bltd :boolean:=true% whether or not the bullet is live or dead
loop Mouse.Where(x, y, b) if x = xPos and y > yPos then
t :=270 elsif x < xPos and y = yPos then
t :=0 elsif x = xPos and y < yPos then
t :=90 elsif x > xPos and y = yPos then
t :=180 elsif x = xPos and y = yPos then
t :=0 elsif x > xPos then
t :=arctand((y - yPos) / (x - xPos)) + 180 else
t :=arctand((y - yPos) / (x - xPos)) endif % This thing here calculates your angle. It'll make sense if you've ever done vectors before. It uses the function tan-1. The ones before it are for mathematical correctness; you cannot divide anything by zero.
if b =1and bltd =truethen% Only shoots when the bullet is dead and the button is clicked.
bltd :=false
bltx := xPos - (40*cosd(t))% setting the position of the bullet
blty := yPos - (40*sind(t))% same
bltvx := -5*cosd(t)% setting the change in x
bltvy := -5*sind(t)% setting the change in y endif
Draw.FillOval(xPos, yPos, 20, 20, blue) Draw.ThickLine(xPos, yPos, xPos - round(40*cosd(t)), yPos - round(40*sind(t)),4, 7)% This is important for drawing shapes according to an angle. You add onto the original postion. In the case of x, its the radius * cos(angle). For y it's radius * sin (angle) if bltd =falsethen Draw.FillOval(round(bltx),round(blty),4, 4, brightred) Draw.FillOval(round(bltx),round(blty),2, 2, 7)
bltx += bltvx % Changes the bullet x position relative to the change in x
blty += bltvy % Changes the bullet y position relative to the change in y if bltx > maxxor bltx < 0or blty > maxyor blty < 0then% If the bullet hits the edge, it dies
bltd :=true endif endif View.Update cls endloop