3

I am trying to implement and understand how to perform a simple translation in GLSL. In order to do that, I am making a simple test in Octave to ensure that I am understanding the transformation itself.

I have the following vector that represents a 2D coordinates embedded into a 4 dimension vector:

candle = [1586266800, 11812, 0, 0]

Which means that the point has locations x=1586266800 and y=11812.

I am trying to apply a translation using the following values:

priceBottom = 11800
timestampOrigin = 1586266800

Which means that the new origin of coordinates will be x=1586266800 and y=11800.

I build the following translation matrix:

[ 1 0 0 tx ]
[ 0 1 0 ty ]
[ 0 0 1 tz ]
[ 0 0 0 1  ]

translation1 = [1, 0, 0, -timestampOrigin; 0, 1, 0, -priceBottom; 0, 0, 1, 0; 0, 0, 0, 1]

Is this matrix correct? How shall I apply it to the vector?

I have tried:

>> candle * translation1
ans =
1.5863e+009  1.1812e+004  0.0000e+000  -2.5162e+018

Which obviously does not work.

M.E.
  • 4,955
  • 4
  • 49
  • 128

1 Answers1

2

Your translation is wrong. From a mathematical point of view, the transformation you're after is:

i.e. you need to 'augment' your vector with another dimension with the value 1, so that it can be used to add the 'translation' information to each row during matrix multiplication.

So, if I understood your example correctly

Initial_position   = [1586266800; 11812; 0; 0]   # note: vertical vector
Augmented_vector   = [Initial_position; 1]
Translation_vector = [0         ; -12  ; 0; 0]   # note: vertical vector

Transformation = eye(5);
Transformation( 1:4, 5 ) = Translation_vector

Translated_vector = Transformation * Augmented_vector;
Translated_vector = Translated_vector( 1:4, 1 )
Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57
  • I think OP has a 3D vector that is already augmented, though there is a 0 instead of a 1 in that place. – Cris Luengo Apr 10 '20 at 00:47
  • Thanks, as @cris-luengo states the 3D vector is already augmented and there was a 0 instead of a 1. Mixing the answer and the comment clarifies the operation. – M.E. Apr 10 '20 at 09:23
  • @cris-luengo A follow-up question with the actual GLSL problem: https://stackoverflow.com/questions/61138427/how-do-i-implement-two-translations-and-a-scale-operation-in-glsl – M.E. Apr 10 '20 at 10:33