TransformVector in simple terms

Blitz3D Forums/Blitz3D Programming/TransformVector in simple terms

Lane(Posted 2003) [#1]
Could someone explain to me as if I was a 4 year old how TransformVector works.
Or perhaps in what situation you would use it?

I was looking for a way to find a point in 3d space that is 900 units ahead of my Entity using its current XLoc YLoc XVel YVel. ZLoc never changes. I would like to do this WITHOUT actually moving the entity, fetching it's quardinants, and then moving it back.

My current experiments give me a point just off of 0,0 .

The documentation and examples (to me) seem pretty lacking in clarity. I'm assuming by the lack of details that I'm just making it much harded than it is.


Lane(Posted 2003) [#2]
This helps a little.
http://www.blitzbasic.com/bbs/posts.php?topic=16442


jhocking(Posted 2003) [#3]
I'm not sure exactly what you are trying to do (your description is inconsistent; if want 900 units ahead then why does velocity matter?) but I don't think you need TFormVector. TFormPoint would be more useful but even that probably isn't necessary. I do a similar thing by placing a pivot ahead of the entity and parenting it to the entity right when I load the model, before it moves. Then whenever I want the location ahead of the entity I just get EntityX() and what not for the child/pivot. Plus, considering your movement is constrained, you may be able to just do the math yourself. You refer to ZLoc never changing; if the rotation never changes EXCEPT on Z (ie. movement is constrained to 2 dimensions) then the problem is simple trigonometry. I'm sure you learned the Pythagorean theorum in high school.

At any rate, put simply TFormVector (and TFormPoint, only referring to a point and not a vector obviously) takes a vector defined within one coordinate system and returns an identical vector but defined within a different coordinate system. To give the most common example, you may have a vector defined relative to the player (eg. straight forward.) You can use the TForm commands to get the same vector but defined relative to world coordinates to determine the global position/movement/whatever defined by the vector.

Actually, the most common thing I use TFormVector for is camera relative movement. For example, no matter which way the camera is facing I want the left arrow key to face the character left relative to the camera. Thus I have to transform the left vector from the camera's local coordinates to world coordinates in order to find the direction to face.

As for your problem, you could find the point relative to the player and then use TFormPoint to find the global coordinates of that point. Like I said though this is probably overkill.


Lane(Posted 2003) [#4]
jhocking> "if want 900 units ahead then why does velocity matter?"
A< Because having the current x and y location doesn't tell you what direction the entity is moving. Actually I meant vector. X and Y Velocity would give be rate of movement in what direction but I only need really need the direction assuming that the rate of movement is always considerably less than 900.

My alternative at this point is to keep track of the current and last cycles X and Y locations and use that to calculate 900 units out in the direction of movement derived by if the new locations are greater or less than the old locations.

I was hoping that one of the TForm commands would provide this and it appears that TFormedPoint will give me the correct global location if I use it like this.
TFormPoint 0,900,0,Ship1,0
If I understand this correctly it will set TFormedX TFormedY and TFormedZ to the global quardinates of 900 units ahead of my ship.

Your description of what they are for describes it much better than the help files. Thanks.


Lane(Posted 2003) [#5]
Can someone clarify this please? My assumtion appears to be incorrect that "TFormPoint 0,900,0,Ship1,0" should return a world addressed point 900 units ahead of my ship but rather it returns a point only a few pixels ahead of it. :(


jhocking(Posted 2003) [#6]
Are you sure Y is ahead? Depending on how your mesh is oriented it could be any of the three axes; make sure to try them all.


Lane(Posted 2003) [#7]
I see what your saying where as the point returned might be 900 on the Z but only a few on the Y and appear as only a few pixels ahead of my ship. Possibly. I'll add debug code so I can verify the returned position.


jhocking(Posted 2003) [#8]
Unless compiles are taking a long time there's no need for debug code. Just try changing the TFormPoint command and see what happens. Specifically, change which axis you are checking 900 ahead on.


Lane(Posted 2003) [#9]
Found my solution.
Since I have a source dust sprite that I make copies from, While intitializing the environment I move the source dust sprite to the point 900 units ahead of the ship and then make the ship a parent to the dust sprite so it moves and rotates with it. Then I calculate the new dust positions based on the source dust's global coordinates.
I'm note sure at this point which is more processor optimized.
a: Having an entity constantly being updated in memory as a child to the ship.
or
b: Calculationg a new position based on the current ship coordinates as needed.

Seems like option B would be a better use of memory and processor time but then that has to do with how often a dust is moved.

I would like to find a function that will return the global position of the ship 900 untis ahead without actually using the processor time consumed by moving the ship, getting the coordinates, and then moving the ship back to it's original location.