Programming formulas

D

Dark-Angel

Guest
lets say i have a bunch of formulas i want to use, most of them are physique formulas.

1 how would i program them
2 how do i use the out come of the formula
3 how do i creat variables for the formula, like lets say i want to do ballistic, so i need to be able to program gun with variable i need to fill in like, muzzle velocity, bullet weight...
4 this is unknow for now, but base on old HL engine how would i use the formulas to affect bullets, then make an other one for rockets...
 
this is like saying, 'i know what i want to draw, how do i draw it?'

you're going to have to give us a little more than that.
 
can you show me any places that explain how to use this? cause i have no idea how to program thoes :(
 
This will depend on the formula. If it is a simple formula like S=D/T that you are trying to code then just change the subject (ie. put the letter you are trying to calculate at the front)... for example if it is D then the forumla becomes D=ST (hopefully you can remember this from school). To code, as follows (note my total lack of conventions) ...

inline float CalcDist(float inSpeed, float inTime) {
return inSpeed * inTime;
}

Thus you can get the distance from some other code (that knows the speed and time) by calling that function. The above example could be used to calculate how far to advance a bullet given the speed of the bullet and the dT since last advancement.

If the formulas are more complicated (ie. perhaps differential) then you will need to locate the algorithm for computing the result first, and then code that.
 
I think it was for a game re: "base on old HL engine how would i use the formulas to affect bullets" but I don't have knowledge of coding for HL1 so I can't really help with that.
 
formulas i got are a little more complicated then what you said hehehe. sy = syi + tanOr(sx) + 1/2(g) x (sx2) / ((vr)(cosOr))2 this is an example. some are a little more complicated. I tough if some one had an idea how to program it in HL1 shouldnt be to diffrent with HL2 oh well in HL i think i can base my self on the crossbow for creating a bullet. Any way i think im going to buy a book on Ballistics to be sure i got what i need for formulas.
 
see all your letters? make them variables, and plug it all in. thats all there is to it.
 
yes... but when you got cos, sin, log and stuff like that no idea how im supose to program thoes things.
 
math. h has all the trigonometric functions (cos, sin and tan), and the exponential functions (exp, log, log10). As for sec, cosec and cot you can do that by reciprocating a trig function. If you have MSVC 6.0 you probably have math.h in one of the include folders.

If you don't have math.h, the only one I could help you with is the exp() function (which returns e to the power of a number). Although it would be interesting to find out how to write a ln or log function or a sin/cos function....
 
worst come to worst. . .
cin<<adjacent
cin<<opposite
opposite/adjacent + opposite%adjacent
to find tangent :D.

Then again its a curve and not a perfect triangle, but thats what we use in our physics class anyway :\

side note, its pretty weird how a triangle can have three 90 degree angles. on a globe if you have a point at the north pole, then another 2 points that are equally distanced from each other and the north pole on the prime meridian. 3 equal sides, 3 equal angles of 90 degrees X_X
 
If anybody wants I have functions that approximate ln(x) and e^x (although the latter isn't working correctly, the actual way it works is pretty simple so you might be able to code it yourself).
 
Back
Top