EnglishGermanFrenchRussianPolishItalianSpanish
Log inRegister
 
Code Logic Question
Post new topic Reply to topic Goto page 1, 2  Next
View previous topic :: View next topic
Author Message
EmperorJon



MEDAL

Joined: 29 Dec 2008
Posts: 6665 on topic
Location: Leicester
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 22:59    Post subject: Code Logic Question Reply with quote Print

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
View user's profile Send private message Send e-mail Visit poster's website
Gazz
Moderator (Script&Mod)
Moderator (Script&Mod)



Joined: 13 Jan 2006
Posts: 12152 on topic
Location: Bavaria
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:06    Post subject: Reply with quote Print

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
View user's profile Send private message Visit poster's website
EmperorJon



MEDAL

Joined: 29 Dec 2008
Posts: 6665 on topic
Location: Leicester
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:10    Post subject: Reply with quote Print

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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
InFlamesForEver





Joined: 22 Jul 2011
Posts: 509 on topic
Location: Essex, Mighty England
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:12    Post subject: Reply with quote Print

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!! Very Happy     ¹ ¤ ¹      But, the nuns are watching...
Samuel Creshal wrote:
Keyboards: What separates the men from the boys.
Back to top
View user's profile Send private message
Samuel Creshal



MEDAL

Joined: 06 Mar 2004
Posts: 4318 on topic
Location: Graz, Austria
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:15    Post subject: Reply with quote Print

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 Razz


_________________
Microsoft is not the answer. Microsoft is the question. NO is the answer.
Devchat UI | YakiMinecraftServer
Back to top
View user's profile Send private message Visit poster's website
Gazz
Moderator (Script&Mod)
Moderator (Script&Mod)



Joined: 13 Jan 2006
Posts: 12152 on topic
Location: Bavaria
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:21    Post subject: Reply with quote Print

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
View user's profile Send private message Visit poster's website
EmperorJon



MEDAL

Joined: 29 Dec 2008
Posts: 6665 on topic
Location: Leicester
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:33    Post subject: Reply with quote Print

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
View user's profile Send private message Send e-mail Visit poster's website
Chips





Joined: 19 Mar 2004
Posts: 670 on topic
Location: UK
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:37    Post subject: Reply with quote Print

Without a code example, kinda hard to help. No idea what you've done so fa Razz

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...


_________________
Guides, Help and Walkthroughs
X3 Reunion tutorial - Starter controls and Mission 1 & 2 Walkthrough
Back to top
View user's profile Send private message Visit poster's website
EmperorJon



MEDAL

Joined: 29 Dec 2008
Posts: 6665 on topic
Location: Leicester
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:41    Post subject: Reply with quote Print

Yeah, it'll end up being taped together with matrices I dare say... Wink


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. Razz


_________________
_______________________________
The Trade Plugin - Finally out of Beta.
STFUnit - Military Plugin
Find All Crates/Ships!
I Feel Like Killing GoD.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Gazz
Moderator (Script&Mod)
Moderator (Script&Mod)



Joined: 13 Jan 2006
Posts: 12152 on topic
Location: Bavaria
Thank you for registering your game
modified
PostPosted: Wed, 11. Apr 12, 23:54    Post subject: Reply with quote Print

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
View user's profile Send private message Visit poster's website
Tsar_of_Cows





Joined: 31 Jan 2004
Posts: 2209 on topic
Location: Off Topic
Thank you for registering your game
PostPosted: Wed, 11. Apr 12, 23:55    Post subject: Reply with quote Print

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
View user's profile Send private message MSN Messenger
berth



MEDAL

Joined: 06 Nov 2004
Posts: 607 on topic
Location: rhubarb
Thank you for registering your game
PostPosted: Thu, 12. Apr 12, 00:13    Post subject: Reply with quote Print

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
View user's profile Send private message
InFlamesForEver





Joined: 22 Jul 2011
Posts: 509 on topic
Location: Essex, Mighty England
Thank you for registering your game
PostPosted: Thu, 12. Apr 12, 05:07    Post subject: Reply with quote Print

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 Razz

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!! Very Happy     ¹ ¤ ¹      But, the nuns are watching...
Samuel Creshal wrote:
Keyboards: What separates the men from the boys.
Back to top
View user's profile Send private message
EmperorJon



MEDAL

Joined: 29 Dec 2008
Posts: 6665 on topic
Location: Leicester
Thank you for registering your game
PostPosted: Thu, 12. Apr 12, 10:23    Post subject: Reply with quote Print

Visual Basic is not for making games! Razz


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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Samuel Creshal



MEDAL

Joined: 06 Mar 2004
Posts: 4318 on topic
Location: Graz, Austria
Thank you for registering your game
PostPosted: Thu, 12. Apr 12, 10:28    Post subject: Reply with quote Print

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic Reply to topic Goto page 1, 2  Next
 
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
Control Panel
Login Data
The time now is Sun, 19. May 13, 19:06

All times are GMT + 2 Hours


Board Security

Copyright © EGOSOFT 1989-2009
Powered by phpBB © 2001, 2005 phpBB Group
Template created by Avatar & BurnIt!
Debug: page generation = 1.56345 seconds, sql queries = 76