In this game I'm doing, i need to throw an object given values for angle of elevation and velocity. The problem is that I need to draw the object's path. I'm thinking using those numbers to graph a parabola or something to that effect. Could someone help me out on the formula? It would be very helpful.
Okay, let me refine my question. I worked on it myself while waiting for someone to reply. I am in Physics right now in school so I had those two formulas also and everything is worked out except for the time variable. The problem is I don't want to use real time, like tickcounts or whatever. I am trying to work out a way with figuring out how many seconds per pixel and then doing the equation for each pixel but I'm messing up somewhere. I don't know if anyone can understand that but it's worth a shot; I'm giving myself a major headache.
Public Function Throw(Angle As Double, Velocity As Double) As Boolean
'frmSpace.Cls
Dim Vx As Double, Vy As Double, h As Double, d As Double, t As Double, second As Double, x As Double, y As Double
Angle = Angle * (3.14159265358979 / 180)
Vx = Cos(Angle) * Velocity
Vy = Sin(Angle) * Velocity
Do
h = Vy * t - 0.5 * 6.3 * (t * t)
d = Vx * t
y = frmSpace.ScaleHeight / 2 - h
x = frmSpace.ScaleWidth / 2 + d
If y < 0 Or y > frmSpace.ScaleHeight Or x < 0 Or x > frmSpace.ScaleWidth Then Exit Do
SetPixelV frmSpace.hdc, x, y, vbYellow
t = t + 0.025
Sleep 10
Loop
End Function
The reason I was getting all complicated with time was an attempt to have my line drawn at a velocity proportional to that of the actual datum. The sleep API saved my butt, because all I do to change the speed of the line is change the number for sleep. I guess the code should actually have a variable name instead of 10.
The problem with creating curves from mathematical functions is that your screen is based on integer maths (pixels) and your curve is probably not.
If I were you I would try to do an inverse mapping rather than a forward mapping - it's hard to explain it in this context but basically it means you calculate what a pixel is meant to be like from an algorithm, rather than using an algorithm to decide where pixels should go. It means you don't get gaps in your line, and you do the minimum number of pixel plots.
You can divide you parabola into either 1 section (if it has an initial angle of elevation of 45 degrees or less) or 3 sections (if it's between 45 and 90 degrees). If its velocity is always 45 or less degrees from the horizontal, then you can calculate from each X coordinate what the corresponding Y coordinate should be, and plot each pixel at those coordinates.
If it is split into 3 sections, those sections of the line will look something like this (excuse the ASCII art):
Code:
| | X X |
| | X X |
| | X X |
| |X X|
| X| |X
| X | | X
| | |
| X | | X
|____|_______________________________|______
A B
Say the X's are points on your function. The vertical lines A and B divide the curve up into 3 sections. Before A and after B, the absolute value of the angle is greater than 45 degrees. In these regions, you take each y coordinate and calculate the closest corresponding x coordinate. This is so that you don't get gaps in the line. In the middle section, you do it normally as I said for 1 section.
You could set scalemode to 0-user and do scrolling and zooming of the view, and the coordinates will hit without convertions. The derived formulas for constant accleration is
sum of displacement in position, displacement in velocity by time and half of displacement in acceleration by time^2 is zero, for each dimension component in a n dimensioned coordinate systems
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
i'll try and attach my project so you can see it work. give me a few days to finish off the tank class. right now i'm having a little trouble with calling the fire method. gonna check around, see what i'm doing wrong, then I'll put it up.