Raised This Month: $ Target: $400
 0% 

String manipulation fun!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flynn
Senior Member
Join Date: Sep 2009
Old 09-23-2009 , 08:28   Re: String manipulation fun!
Reply With Quote #1

Quote:
Originally Posted by Greyscale View Post
Works out the speed based on mass and distance from each other? What speed?
Sorry, I should have provided context. Space.

Typically all objects have a continuous although very very very slight gravitation pull at a distance (apparently far away black holes have the same impact as the 'beating of a gnat's wings', if I recall correctly) which increases as the objects get closer.

My function was a lot simpler; drawing two objects together based on mass. One student had told me writing such a function was impossible (I doubted that given gravity exists and that's technically a 'mathematical function'). I missed out on physics and mathematics largely (which is a pity - I enjoyed both), but I figured speed = (mass1 + mass2)/distance (if I recall correctly) and started working on momentum and potential momentum (as all objects would gain so much speed they would overshoot on every pass). I noticed gravitation pull had 'rings' and as you pass each one, the speed would exponentially increase. Although my theories and that of other people rarely coincide.

I throw this up here as inter-related gravitation pull of various interstellar objects would be incredibly useful, whether as studying for physics generally or a more specific space-based game (I had ideas for the latter but various things meant I abandoned the project).

I'd say stick to the 2D axis, as 3D axis can be expanded from the 2D axis (if we start 3D we would have too many variables to keep track of).
Quote:
Originally Posted by PM View Post
Haha, I would still just love to know what need there is to abuse that logic if the OR operator does exactly what you want without abusing any logic -- or is it just to be more obscure?
I suppose to be more obscure. An OR operator could work in it's place, but I find adding booleans makes the code look more interesting. Plus, I wouldn't have learnt anything if I hadn't.

Bitwise physics abuse. The problem with me doing anything physics as I previously mentioned is I missed out on both physics and mathematics. I can quickly grasp and create new theories rapidly, so the physics isn't such a biggie; it's the mathematics. I might have an idea that could calculate the universe, but without knowing mathematical functions I wouldn't be able to write it (or would get bogged down re-writing mathematical functions).

Even my barrel launcher based on client eye angles uses my own written calculus to work out the directional velocity because I don't know anything about functions that convert angles to co-ordinates...

PHP Code:
    GetClientEyeAngles(client,ang);
    
    
answer ang[1];
    
    if(
RoundToFloor(answer) > -181 && RoundToFloor(answer) < 0)
    {
        
answer float(RoundToFloor(answer) * -1)
    }
    
    if(
RoundToFloor(answer) < 91 && RoundToFloor(answer) > -1)
    {
        
answer float(90 RoundToFloor(answer));
        
vel[0] = float(40 RoundToFloor(answer));
    }
    
    if(
RoundToFloor(answer) > 90 && RoundToFloor(answer) < 181)
    {
        
answer float(RoundToFloor(answer) - 90);
        
vel[0] = float(-40 RoundToFloor(answer));
    }
    
    
answer ang[1];
    
    if(
RoundToFloor(answer) < -91 && RoundToFloor(answer) > -181)
    {
        
answer float(-180-RoundToFloor(answer));
    }
    
    if(
RoundToFloor(answer) > 90 && RoundToFloor(answer) < 181)
    {
        
answer float(180-RoundToFloor(answer));
    }
    
    if(
RoundToFloor(answer) > -91 && RoundToFloor(answer) < 91)
    {
        
vel[1] = float(40 RoundToFloor(answer));
    }

    
vel[2] = float(-40 RoundToFloor(ang[0])); 
It's not like it's non-functional (quite the opposite, it's quite precise), just it's a wasted effort figuring out formulae for something that's already done. I just can't learn mathematics because it truly is written like absolute gibberish. It's the only subject area who's language I know makes up symbols or steals other symbols whether they want to represent whatever they can't be arsed to explain because it's too damn complex.
Quote:
Originally Posted by Theme97 View Post
However, I could really use something similar to this (given object A, point B, and X frames, move A to B but only decelerate; 2D) for another plugin of mine, so it would be nice to know what algorithm to use.
You don't need to know physics or mathematics to get what you want, but it helps.

Simply put, you get the two co-ordinates, using py's theorem (Which is two X co-ords added together times by themselves, the two Y co-ords added together times by themselves, add the two answers, square root the answer), calculate the distance between the two, divide that distance by the speed so you get the frame spacing (these are sometimes called 'steps').

This is the part I can't tell you how to do (although there are mathematical functions for this), calculate the angle between the two points and the horizontal line, then convert the angle into co-ordinates by combining (again with a mathematical function) angle with the frame spacing/steps, and keep running those steps until you change the speed, when you'll need to recalculate the steps.

Change speed over time by storing the time it starts, seeing the elapsed time since starting, whether or not it exceeds X, increasing it and resetting it if it has.

Edit: Thats wrong. That's acceleration. Deceleration would be division. To change speed just modify the speed and recalculate the steps.

In short?

Speed = Speed + (X.Units * Time.Units)
Distance = ((X+X2)* + (Y+Y2)*)(SquareRoot the answer)
Steps = Distance/Speed
Current X,Y = Steps+Angles (Not literally add - you need to combine to two using RadToSine or whatever).

Done. But this is what I mean about my lack of mathematical knowledge.

Last edited by Flynn; 09-23-2009 at 08:33.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Theme97
Senior Member
Join Date: Mar 2009
Old 09-23-2009 , 18:27   Re: String manipulation fun!
Reply With Quote #2

Well, my approach now.

Since this is in TF2, I've got to used 3D coords but I set everything on the Z axis equal to each other.

So, given:
- Float:start[3]
- Float:end[3]
- Float:deceleration (positive) = -a
- frames = t

Then under the formula vf = vi + at
Since vf is 0, we can conclude that vi = -at

So, for Float:velocity and Float:accel,
PHP Code:
MakeVectorFromPoints(startendvelocity);
NormalizeVector(velocity);
accel velocity;
ScaleVector(velocitydecel frames);
ScaleVector(accel, -deceleration); 
From there on, it's just a matter of doing
PHP Code:
AddVectors(velocityaccelvelocity); 
every game frame which ends up sounding a lot easier than what you had suggested. D:

---

Edit: Also, angle between two vectors v1 and v2:

In code:
PHP Code:
stock Float:AngleBetweenVectors(const Float:a[3], const Float:b[3]) {
    return 
ArcCosine(GetVectorDotProduct(ab) / (GetVectorLength(a) * GetVectorLength(b)));

__________________
I now have very little time to work on stuff and my main computer (which is the only one that can run TF2) is not cooperating with me, so don't expect many updates from me anytime soon.

[ALL] Karaoke
[TF2] Intel Timer | Crabmod | Randomizer | Stopwatch | Crits 4 All

Last edited by Theme97; 09-24-2009 at 00:17.
Theme97 is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-23-2009 , 19:24   Re: String manipulation fun!
Reply With Quote #3

Quote:
Originally Posted by Theme97 View Post
Also, angle between two vectors v1 and v2:

In code:
PHP Code:
stock Float:AngleBetweenVectors(const Float:a[3], const Float:b[3]) {
    return 
ArcCosine(GetVectorLength(a) * GetVectorLength(b) / GetVectorDotProduct(ab));

Isn't that exactly the wrong way round? This way you'd be dividing by zero for 90 degrees.
AFAIK it should be arccos( v1 dot v2 / (||v1|| * ||v2||) ) .
__________________
hello, i am pm
PM is offline
Theme97
Senior Member
Join Date: Mar 2009
Old 09-24-2009 , 00:16   Re: String manipulation fun!
Reply With Quote #4

Quote:
Originally Posted by PM View Post
Isn't that exactly the wrong way round? This way you'd be dividing by zero for 90 degrees.
AFAIK it should be arccos( v1 dot v2 / (||v1|| * ||v2||) ) .
Ahah, thanks for pointing out the fail.

Edited.
__________________
I now have very little time to work on stuff and my main computer (which is the only one that can run TF2) is not cooperating with me, so don't expect many updates from me anytime soon.

[ALL] Karaoke
[TF2] Intel Timer | Crabmod | Randomizer | Stopwatch | Crits 4 All
Theme97 is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-24-2009 , 04:55   Re: String manipulation fun!
Reply With Quote #5

Quote:
Originally Posted by Greyscale View Post
You want to find the gravitational pull between 2 objects?

Simple.

Fg = G((m1*m2)/r^2)

I believe that's it.
I'll have to look up G. It's some tiny constant I can google it right now... 6.67300 × 10^-11 m^3 kg^-1 s^-2

You can ignore those intimidating units.

m1/2 are the masses of the objects and r is the radius. The distance between the objects. It's refered to as radius because normally your calculating from the center of a large mass such as earth.

This equation is how you derive the -9.81 m/s^2 constant for earth.

Fg is the force of gravity, in newtons. That's pretty much all I can think that you need to know.

Here's a more in-depth description: http://en.wikipedia.org/wiki/Gravitational_constant
Those kinds of theories make my eyes glass over. Besides I'm sure density of the matter would be involved (probably in the process of the ...
{
Hold on a minute. Light is apparently 'massless'? So how does a dense black hole pull it in if there is no mass in which to...

Or, unless light does have a mass, which means mass can travel at the speed of light. Which means we could slow down time for an object... just be a little... gooey... on the other end. Unless of course you just send information. Information can't be crushed.

(This is how my brain works!)
}
... mass itself) however, it's easier to just give it X mass and use that as the force as well (although it isn't very scientific, games don't have to be unless you're trying to precisely simulate something).

But what about multiple units? What direction does a mass head in based on the pull of two (or more) objects? Well, probably in the direction of the strongest mass, but, how do we effectively calculate that?

Wouldn't it be easier to combine the force of two or more objects and have that influence the object at greater distances and then as it gets closer make them separate?
Quote:
Originally Posted by Theme97 View Post
Since this is in TF2, I've got to used 3D coords but I set everything on the Z axis equal to each other.
It's the same method but you have to factor in angle calculations on the other 'planes'. And probably would need a way to combine the three calculated distances of the three separate triangles (again, one for each plane) or something.

But that's sketchy at best. I haven't even done the 2D version let alone the 3D one.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Frus
Senior Member
Join Date: Aug 2009
Old 09-24-2009 , 05:05   Re: String manipulation fun!
Reply With Quote #6

Quote:
Originally Posted by Flynn View Post
But what about multiple units? What direction does a mass head in based on the pull of two (or more) objects? Well, probably in the direction of the strongest mass, but, how do we effectively calculate that?

Wouldn't it be easier to combine the force of two or more objects and have that influence the object at greater distances and then as it gets closer make them separate?
You determine it using simple force and vectors physics. Basically just make all forces on an object into vectors, then add up the vectors.

i.e. in 1D If object x has a +5N force, and a -3N force on it, object x has a net force of +2N. You can then calculate the resultant acceleration from the force using f = ma. basically divide the net force in N by the mass of the object in kg to get the acceleration of the object caused by the forces on the object.

I'm not sure what you mean by the second paragraph, but yes, you simplify all forces to one net force no matter how far or close they are.

As far as light goes, that's a subject all into itself, it's not as simple as saying light has a mass or light does not have a mass.

Last edited by Frus; 09-24-2009 at 05:07.
Frus is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-24-2009 , 05:24   Re: String manipulation fun!
Reply With Quote #7

Quote:
Originally Posted by Frus View Post
You determine it using simple force and vectors physics. Basically just make all forces on an object into vectors, then add up the vectors.
Seems awkward. I'd probably have to blow up my brain drawing a hypothetical scenario on a peice of paper of 2D space and trying to work out how, if I was X object, how I would move (or be expected to move) in relation to other objects.

Quote:
Originally Posted by Frus View Post
As far as light goes, that's a subject all into itself, it's not as simple as saying light has a mass or light does not have a mass.
It's a wave! No it's a beam! It's both a beam and a wave!

I'm one of those people who categorise things into one box or another. And I'd probably say it is (who am I to say such things about time and space?). I just find such a thing works quite nicely.

Beside, if mass generates gravity, and gravity can only pull mass, and a black hole is a super-dense, super-gravity-magnifying-time-bending-object that stops light escaping, then light must have a mass (a mass so small it's practically unreadable but due to the sheer power of the 'black' hole is magnified enough to pull it in).

Besides, energy needs a storage medium. Most common universal medium is typically... yeah. Which implies something about energy.

Besides, I don't build these theories so people can agree with them (I rarely expect people to do so). The real theory currently pre-occupying my mind (which I think is actually, as strange as it sounds, more important than light or physics at the moment) is what is luck and what influences it?

And don't give that 'be more observant of opportunities' crud that people are churning out. Of course being observant gives you more resources but luck isn't defined by 'resources' or opportunities. If that was the case I'd be lucky simply for having a magnifying glass and a sherlock holmes persona (and admit it - how many lucky people are like this?). I mean, how exactly do you observe the lottery anyway?

If it was observation I would be pretty lucky by now. But I'm not. Oh horribly not so.

Last edited by Flynn; 09-24-2009 at 05:26.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode