Jump to content




3D Engine transformation matrix help


  • You cannot reply to this topic
4 replies to this topic

#1 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 14 December 2015 - 06:34 PM

Hi guys,

I have been working on a 3D engine for a week now, and I am having some questions.

When I rotate the object (using a left handed coordinate system), the points move in a weird manner. Instead of staying on the circle, they come inwards:

Posted Image

There are two "parallel" circles because there are tow points. The main concern is that the points come inwards.

This is the code I use for the matrix:

rotateZ = function(dergees)
  local radians = rad(dergees)
  local c = math.cos(radians)
  local s = math.sin(radians)
  --[[return {
    c, s, 0, 0,
   -s, c, 0, 0,
    0, 0, 1, 0,
    0, 0, 0, 1,
  }]]--
  return {
   ["1_1"] = c,
   ["1_2"] = s,
   ["2_1"] = -s,
   ["2_2"] = c,
  }
end,

This is the code I use for multiplying the matrix with the position vector (x,y,z,w):

rotateZ = function(matrix)
   x = x*matrix["1_1"] + matrix["1_2"]*y
   y = x*matrix["2_1"] + matrix["2_2"]*y
  end,

I have striped the useless operations away to make it faster, much faster.

The questions:
  • Why does the circle go inwards?
  • Is this the correct transformation matrix for rotating around the Z axis on a left hand coordinate system?
  • What exactly does w (in the position vector) represent and why is it useful?
  • What is the translation matrix?

Thanks in advance,

Creator.

PS: Before anyone jumps on me saying: "This is not CC!"

I know, I am developing it for Love2D and then porting to CC 2.0

#2 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 14 December 2015 - 09:50 PM

  • Why does the circle go inwards? At a guess, rounding errors or a bug
  • Is this the correct transformation matrix for rotating around the Z axis on a left hand coordinate system? I'm not good at remembering which
  • What exactly does w (in the position vector) represent and why is it useful? uniform scaling
  • What is the translation matrix? A matrix which (if multiplied by a vector/point) will move the vector/point.
If you know C++ feel free to look at my matrix/maths classes. It uses the same coordinate system as openGL, which I believe is left handed.

Edited by Lupus590, 14 December 2015 - 09:55 PM.


#3 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 14 December 2015 - 11:28 PM

Thanks

#4 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 15 December 2015 - 12:01 PM

View PostCreator, on 14 December 2015 - 06:34 PM, said:

rotateZ = function(matrix)
   x = x*matrix["1_1"] + matrix["1_2"]*y
   y = x*matrix["2_1"] + matrix["2_2"]*y
  end,

You overwrite the old x value with a new one, making the second calculation wrong.
rotateZ = function(matrix)
   local oldX = x
   x = x*matrix["1_1"] + matrix["1_2"]*y
   y = oldX*matrix["2_1"] + matrix["2_2"]*y
  end,

Edited by SquidDev, 15 December 2015 - 12:02 PM.


#5 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 15 December 2015 - 12:34 PM

Thanks SquidDev. I seriously don't know how I oversaw that. +1

It works! Just tested it.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users