PDA

View Full Version : Programming formulas


Dark-Angel
28-09-2003, 08:56 PM
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...

rootbin
30-09-2003, 01:01 AM
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.

Tee Kyoo Em
30-09-2003, 01:27 AM
Dark-Angel: You will have to map the mathematical formulas into the domain of the specific programming language that you intend to use.

Programming languages like MATLAB were specifically designed to address the needs of technical computing. However, if you intend to use these formulas as part of a game, you will most likely end up with C++.

The outcome and the variables of a formula can be mapped more or less one-to-one to specific C++ data-types, such as matrices, vectors, real/integer numbers, etc. With C++, you can take advantage of existing libraries that already deal with matrix/vector computations and various other algorithms and build upon that for your own work.

Dark-Angel
30-09-2003, 01:59 AM
can you show me any places that explain how to use this? cause i have no idea how to program thoes :(

Tee Kyoo Em
30-09-2003, 02:52 AM
For technical computing, I know of two competing products: Mathematica (http://www.wolfram.com/products/mathematica/) and MATLAB (http://www.mathworks.com/products/matlab/). Descriptions of their languages and mathematical notations should be part of the documentation. These are commercial products, though. Does somebody here know of any freeware alternatives?

If you want to use C++, you will have to learn a fair amount about the language first, before you can start to program algorithms in it and integrate those into a game.

MrD
01-10-2003, 03:18 PM
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.

Tee Kyoo Em
01-10-2003, 05:08 PM
With C++, formulas such as S=D/T and D=ST don't have to be broken down into explicit functions (see CalcDist) by the programmer. That job can be left to the compiler. Using specific data types (matrices, vectors, scalars, etc.) and operator overloading, S=D/T; and D=S*T; are valid C++ statements.

Unless Dark-Angel wants to use these algorithms in a game, he (she?) is better off using an appropriate program for numerical computations that allows for standardized mathematical notations.

MrD
01-10-2003, 10:01 PM
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.

Dark-Angel
02-10-2003, 12:53 AM
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.

nnyexoeight000
03-10-2003, 09:25 PM
see all your letters? make them variables, and plug it all in. thats all there is to it.

Dark-Angel
06-10-2003, 12:10 AM
yes... but when you got cos, sin, log and stuff like that no idea how im supose to program thoes things.

Nith Sahor
06-10-2003, 12:31 AM
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....

sensurround
06-10-2003, 12:40 AM
oh

Orange
12-10-2003, 07:53 PM
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

Nith Sahor
14-10-2003, 03:37 AM
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).