|
|
 |
View previous topic :: View next topic |
 |
|
|
|
|
Author |
Message |
|
|
|
|
|
EmperorJon

Joined: 29 Dec 2008 Posts: 6665 on topic Location: Leicester

|
Posted: Wed, 11. Apr 12, 22:59 Post subject: Code Logic Question |
|
|
This one has me stumped.
Yes, I know, it sounds stupidly easy, and it's ovbiously a problem that has been long solved.
Assuming one has an integer coordinate grid, how does one make a 2 dimensional object move gradually to a specific coordinate, when it's NOT moving in one of the 8 cardinal directions?
Currently my 2 attempts have led to 2 different outcomes; forcing the object to randomly fly around in cardinal directions, and causing it to beeline for the point it's told to go for... but then reach a point where the precision causes all problems and it just hovers backwards and forwards. (Seems to be going "Move one step. Now that's too far, move one back. Ok, try Y now. Nope, and X? Nope. Ok, I'll just keep doing this.)
_________________ _______________________________
The Trade Plugin - Finally out of Beta.
STFUnit - Military Plugin
Find All Crates/Ships!
I Feel Like Killing GoD. |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
Gazz Moderator (Script&Mod)


Joined: 13 Jan 2006 Posts: 12152 on topic Location: Bavaria

|
Posted: Wed, 11. Apr 12, 23:06 Post subject: |
|
|
You have 2 vectors. Take the higher ABS(scalar) of those.
Your object moves in [scalar] steps = n.
x.vector = ( n * x.vector.total ) / scalar
y.vector = ( n * y.vector.total ) / scalar
If the integer overflow doesn't get you, that's it.
With X3, you kinda get used to integer math. =)
_________________ My complete script download page. . . . . . Xai-Corp MSCI List is scripter's friend. I AM THE LAW!
Dogs and colour blindness explained: People with green eyes can't see dogs. |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
EmperorJon

Joined: 29 Dec 2008 Posts: 6665 on topic Location: Leicester

|
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
InFlamesForEver

Joined: 22 Jul 2011 Posts: 509 on topic Location: Essex, Mighty England

|
Posted: Wed, 11. Apr 12, 23:12 Post subject: |
|
|
Oh god Gazz. That makes my knowledge of coding (visual basic lol) quiver.
Although, in computing, we seem to do less coding more theory, I hate theory...
_________________ In Flames We Trust
Listening to Whitechapel soothes the soul!! ¹ ¤ ¹ But, the nuns are watching...
| Samuel Creshal wrote: |
| Keyboards: What separates the men from the boys. |
|
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
Samuel Creshal

Joined: 06 Mar 2004 Posts: 4318 on topic Location: Graz, Austria

|
Posted: Wed, 11. Apr 12, 23:15 Post subject: |
|
|
| EmperorJon wrote: |
| I did something every similar to that and it didn't seem to work... |
Code examples might help…
@InFlamesForEver: No theory, crappy code. Crappy code, no fun. Therefore, theory == fun 
_________________ Microsoft is not the answer. Microsoft is the question. NO is the answer.
Devchat UI | YakiMinecraftServer |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
Gazz Moderator (Script&Mod)


Joined: 13 Jan 2006 Posts: 12152 on topic Location: Bavaria

|
Posted: Wed, 11. Apr 12, 23:21 Post subject: |
|
|
| EmperorJon wrote: |
| I did something every similar to that and it didn't seem to work... |
Either not similiar enough or I was talking complete gibberish.
| InFlamesForEver wrote: |
Oh god Gazz. That makes my knowledge of coding (visual basic lol) quiver.
Although, in computing, we seem to do less coding more theory, I hate theory... |
Straight 2D geometry isn't so bad. In one script I use 2.5D math because full 3D would be way too slow as well as not help achieve the actual purpose. That's not because I'm such a math genius but because any more would inacceptably slow down the script for no gain.
_________________ My complete script download page. . . . . . Xai-Corp MSCI List is scripter's friend. I AM THE LAW!
Dogs and colour blindness explained: People with green eyes can't see dogs. |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
EmperorJon

Joined: 29 Dec 2008 Posts: 6665 on topic Location: Leicester

|
Posted: Wed, 11. Apr 12, 23:33 Post subject: |
|
|
| Gazz wrote: |
You have 2 vectors. Take the higher ABS(scalar) of those.
Your object moves in [scalar] steps = n.
x.vector = ( n * x.vector.total ) / scalar
y.vector = ( n * y.vector.total ) / scalar
If the integer overflow doesn't get you, that's it.
With X3, you kinda get used to integer math. =) |
In which case, let me check I'm understanding the above correctly.
I have the X and Y vector. These are NOT integers. (!!)
To I take the higher modulus of the 2 of them.
The x vector is then the number of steps multiplied by the total needed distance / the scalar value... Brainsplosion here I'm afraid. I'm probably talking complete gibberish here.
EDIT: No, they ARE integers. Of course they are. WTH am I on about now.
_________________ _______________________________
The Trade Plugin - Finally out of Beta.
STFUnit - Military Plugin
Find All Crates/Ships!
I Feel Like Killing GoD. |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
Chips
Joined: 19 Mar 2004 Posts: 670 on topic Location: UK

|
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
EmperorJon

Joined: 29 Dec 2008 Posts: 6665 on topic Location: Leicester

|
Posted: Wed, 11. Apr 12, 23:41 Post subject: |
|
|
Yeah, it'll end up being taped together with matrices I dare say...
Gazz, hopefully an example on your part will clear things up for me.
Say I'm at (0,0) and I want to move to (30,17).
I need to do this in steps, however I can't stop at a point that isn't an integer.
The numbers just don't work. There's no integer common factor for them.
Surely this means, unless I want to do it all in one jump, I'm require to stop somewhere that's "close enough" and introduce inaccuracies some how?
EDIT: Well, scrapped it all and I'm going to bed. Too tired for coding. 
_________________ _______________________________
The Trade Plugin - Finally out of Beta.
STFUnit - Military Plugin
Find All Crates/Ships!
I Feel Like Killing GoD. |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
Gazz Moderator (Script&Mod)


Joined: 13 Jan 2006 Posts: 12152 on topic Location: Bavaria

 |
Posted: Wed, 11. Apr 12, 23:54 Post subject: |
|
|
Well, then 30 steps.
x.vector = ( n * 30 ) / 30
y.vector = ( n * 17 ) / 30
It doesn't matter if it's integer or not. There is no iteration "somewhere around" the destination because you can only arrive at the exact destination. You have no choice.
Well, depending on your floating point math you may end up at something like (29,999999 / 16,9999999) but that, too, can be avoided if you care and if it's mission critical.
To do that you'd not be adding rounded values together but instead calculate the entire vector for every step. That way you eventually have maxScalar / maxScalar and no rounding error whatsoever.
_________________ My complete script download page. . . . . . Xai-Corp MSCI List is scripter's friend. I AM THE LAW!
Dogs and colour blindness explained: People with green eyes can't see dogs.
Last edited by Gazz on Thu, 12. Apr 12, 00:03; edited 2 times in total |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
Tsar_of_Cows

Joined: 31 Jan 2004 Posts: 2209 on topic Location: Off Topic

|
Posted: Wed, 11. Apr 12, 23:55 Post subject: |
|
|
| EmperorJon wrote: |
Surely this means, unless I want to do it all in one jump, I'm require to stop somewhere that's "close enough" and introduce inaccuracies some how?
|
Bingo, I'd say.
If you can't get it to integer accuracy you're going to have to allow a margin of error, i.e. "keep moving until you're within 1 of (30,17)" so that if you're at say (30.341, 16.893) then you've arrived. But without knowing exactly what you're doing, it's hard to help.
_________________
 |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
berth

Joined: 06 Nov 2004 Posts: 607 on topic Location: rhubarb

|
Posted: Thu, 12. Apr 12, 00:13 Post subject: |
|
|
With the major caveat that I know piss-all about coding and from a purely conceptual, coordinate geometry-type approach..
could you just go from (0,0) to (30,0) and then to (30,17)? Or are you tied to travelling in a straight line?
|
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
InFlamesForEver

Joined: 22 Jul 2011 Posts: 509 on topic Location: Essex, Mighty England

|
Posted: Thu, 12. Apr 12, 05:07 Post subject: |
|
|
| Samuel Creshal wrote: |
| EmperorJon wrote: |
| I did something every similar to that and it didn't seem to work... |
Code examples might help…
@InFlamesForEver: No theory, crappy code. Crappy code, no fun. Therefore, theory == fun  |
Trust me, in Visual Basic, coding is fun because its, well easy and basic lol
I can make a game in an hour or 2, I looked at a more complex language once, damn, that was scary lol
_________________ In Flames We Trust
Listening to Whitechapel soothes the soul!! ¹ ¤ ¹ But, the nuns are watching...
| Samuel Creshal wrote: |
| Keyboards: What separates the men from the boys. |
|
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
EmperorJon

Joined: 29 Dec 2008 Posts: 6665 on topic Location: Leicester

|
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
Samuel Creshal

Joined: 06 Mar 2004 Posts: 4318 on topic Location: Graz, Austria

|
Posted: Thu, 12. Apr 12, 10:28 Post subject: |
|
|
| InFlamesForEver wrote: |
Trust me, in Visual Basic, coding is fun because its, well easy and basic lol
I can make a game in an hour or 2, I looked at a more complex language once, damn, that was scary lol |
How can you create anything in such a primitive, verbose language? *shudders*
_________________ Microsoft is not the answer. Microsoft is the question. NO is the answer.
Devchat UI | YakiMinecraftServer |
|
|
|
|
|
|
Back to top |
|
|
|
 |
|
|
|
|
|
|
|
 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
 |
|
|
|
|
|