Select a forum English Forums----------------X-UniverseX RebirthX³: Terran Conflict / Albion Prelude - Technical SupportX³: Terran Conflict / Albion Prelude - Scripts and ModdingX³: Reunion, X²: The Threat, X-T and X-BTF - Technical SupportX³: Reunion - Scripts and ModdingX²: The Threat - Scripts and ModdingCreative UniverseTwitter UpdatesOff Topic English Deutschsprachige Foren----------------X-UniversumX RebirthX³: Terran Conflict / Albion Prelude - Technische UnterstützungX³: Terran Conflict / Albion Prelude - Scripts und ModdingX³: Reunion, X²: Die Bedrohung, X-T und X-BTF - Technische UnterstützungX³: Reunion - Scripts und ModdingX²: Die Bedrohung - Scripts und ModdingKreative ZoneOff Topic Deutsch Forum Français----------------Support et AideL'Univers XScript et Modding Forum Italiano----------------L'Universo di XScript e ModdingSupporto TecnicoForum Off Topic Polskie Fora----------------Polskie / Polish X-ForumPolskie / Polish Off Topic Other Languages----------------Česky / Czech X-ForumDansk / Danish X-ForumEspañol / Spanish X-ForumNederlands / Dutch X-ForumPortuguês / Portuguese X-ForumРусский / Russian X-Forum DevNet: General----------------MSCI Reference
 Code Logic Question Goto page 1, 2  Next
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.
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.
EmperorJon

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

 Posted: Wed, 11. Apr 12, 23:10    Post subject: I did something every similar to that and it didn't seem to work...________________________________________________ The Trade Plugin - Finally out of Beta. STFUnit - Military Plugin Find All Crates/Ships! I Feel Like Killing GoD.
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.
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
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.
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.
Chips

Joined: 19 Mar 2004
Posts: 670 on topic
Location: UK

 Posted: Wed, 11. Apr 12, 23:37    Post subject: Without a code example, kinda hard to help. No idea what you've done so fa However, I believe the word you need is: Matrices (Matrix) http://en.wikipedia.org/wiki/Translation_%28geometry%29 http://wally.cs.iupui.edu/n351/3D/matrix.html You can define the points of your object in the form of a matrix... as well as the function you wish to apply to it (translation, scalar, rotation) as another matrix. A bit of matrix math (multiplication) and you get out your new coordinates...
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.
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
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.

_________________
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?
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.
EmperorJon

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

 Posted: Thu, 12. Apr 12, 10:23    Post subject: Visual Basic is not for making games! Anyway, thanks for that, it's very very similar to something I tried earlier, basically by saying "Put it rounded at the next coordinate" then checking if it's 1 away fromt he destination we can cheat it, I think.________________________________________________ The Trade Plugin - Finally out of Beta. STFUnit - Military Plugin Find All Crates/Ships! I Feel Like Killing GoD.
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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 Goto page 1, 2  Next
 Select a forum English Forums----------------X-UniverseX RebirthX³: Terran Conflict / Albion Prelude - Technical SupportX³: Terran Conflict / Albion Prelude - Scripts and ModdingX³: Reunion, X²: The Threat, X-T and X-BTF - Technical SupportX³: Reunion - Scripts and ModdingX²: The Threat - Scripts and ModdingCreative UniverseTwitter UpdatesOff Topic English Deutschsprachige Foren----------------X-UniversumX RebirthX³: Terran Conflict / Albion Prelude - Technische UnterstützungX³: Terran Conflict / Albion Prelude - Scripts und ModdingX³: Reunion, X²: Die Bedrohung, X-T und X-BTF - Technische UnterstützungX³: Reunion - Scripts und ModdingX²: Die Bedrohung - Scripts und ModdingKreative ZoneOff Topic Deutsch Forum Français----------------Support et AideL'Univers XScript et Modding Forum Italiano----------------L'Universo di XScript e ModdingSupporto TecnicoForum Off Topic Polskie Fora----------------Polskie / Polish X-ForumPolskie / Polish Off Topic Other Languages----------------Česky / Czech X-ForumDansk / Danish X-ForumEspañol / Spanish X-ForumNederlands / Dutch X-ForumPortuguês / Portuguese X-ForumРусский / Russian X-Forum DevNet: General----------------MSCI Reference
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou cannot download files in this forum
 Control Panel Login Data The time now is Sun, 19. May 13, 19:06 All times are GMT + 2 Hours