Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 06 Mar 2012
Offline Last Active Jan 15 2016 02:06 PM

Topics I've Started

Vector4 W Component

02 January 2016 - 07:34 AM

I'm working on a Vector4 class, and am having a hard time figuring out what to do with the W Component.


To my understanding if W is 0, the vector is treated as a vector when being multiplied by a matrix. That is, it will not be translated, only rotated and scaled.

If the W is 1, the vector is treated as a point when being multiplied by a matrix. That is, it will be translated, rotated and scaled!


So, what vector operations does W take part in exactly?

I assume not length.... It would be odd if W took part in the Length operation as the vector (2, 2, 2, 0) and the point (2, 2, 2, 1) would have different results.


On that same note, it does not make sense (to me) to include W in the dot product calculation either. 


So, should i just ignore W for these operations: Addition, Subtraction, Scalar Multiplication, Dot Product, Cross Product, Length and Projection?


But then what happens when a Vector with a W of 0 and a Vector with a W of 1 are added? Point + Vector = Point makes sense in my head. But Vector + Point = ? That doesn't really make much sense...


Does this make sense to anyone else? How do you handle the W component of a Vector4?

Confused about row major matrix and pre multiplication

24 February 2015 - 06:23 PM

I'm hoping someone could clear up a bit of matrix confusion i'm having. The breakdown might be because of my understanding of math or direct x but here goes.
As i understand Direct3D is often using a left handed coordinate system, row major matrices and row vectors with pre multiplication.
pre multiplication meaning that the vector being multiplied goes before the matrix.
IE: transformedVector = vector * matrix;
Now as far as i understand given matrices A * B, to calculate the matrix product of element 2, 3 you take the dot product of the second row of A and 3rd column of B. This means that A and B's inner dimensions must match, and their outer dimensions will be the size of the resulting matrix.
With the above rules in mind given a row vector (4, 1) and a transformation matrix (4, 4) the only way to get a row vector as the result is to use post multiplication. That is transformedVector = matrix * vector.
So, given this information how on earth does DirectX use pre multiplication? Do they not follow the row / column rules of the dot product and in effect transpose the vector or matrix?
float4 VertexShader_Tutorial_1(float4 inPos : POSITION ) : POSITION
    return mul(inPos, WorldViewProj );


Row v Column Majors

28 January 2015 - 12:12 AM

I'm a bit confused. I keep reading the following: OpenGL uses a right-handed coordinate system, column-major matrices, column vectors, and post-multiplication.


Yet the in memory layout of an OpenGL matrix is:

x.x x.y x.z 0
y.x y.y y.z 0
z.x z.y z.z 0
p.x p.y p.z 1


x.x x.y x.z 0 y.x y.y y.z 0 z.x z.y z.z 0 p.x p.y p.z 1

Which is a row major layout!


I'm trying to roll my own math library, looking at glm for guidance, matrices are indexed as


which would seem to only further strengthen that OpenGL is indeed using row matrices.


It sounds like the matrix notation used in the OpenGL docs (and blue book) does not describe the in memory layout of the matrices.

Which begs the question, does this mean i should be pre-multiplying matrices, or do i need to account for the in-memory layout when doing matrix multiplications and keep post-multiply?


again, turning to glm for help, if i want to translate a model to 1, 2, 3 and then scale it up by 2 i need to do post multiplication:

glm::mat4 mat = glm::translate(glm::vec3(1.0f, 2.0f, 3.0f)) * glm::scale(glm::vec3(2.0f, 2.0f, 2.0f));
Results in:

2, 0, 0, 0, 

0, 2, 0, 0, 

0, 0, 2, 0, 

1, 2, 3, 1

But, if the matrix has a row layout, shouldn't that multiplication be in reverse?


So confused.....

Visual Studio 2013 _tmain ?

13 June 2014 - 10:23 PM

After several years of not using windows i find myself having to use visual studio 2013 (The last edition i used was visual studio 2008). To my surprise, my simple console application will not compile. It is complaining about a missing _tmain function. After checking out the default project that gets generated, i renames my main function from

 int main(int argc, char *argv[]) {


int _tmain(int argc, _TCHAR* argv[]) {

And everything now works...


When did this change happen?

What was the reasoning behind this? Why not just keep regular old main?


Is there any way to use the standard main function? I hate having #if statements just for windows....


Can anyone please shed some light on this matter for me?

LUA load file into table

07 May 2014 - 03:00 PM

This question relates to the lua c api. Lets say i have a file like this one: 

helloString = "Hello World"

function fwrite (fmt, ...)
     return io.write(string.format(fmt, unpack(arg)))

And i want to load it into a global table named loadedScript such that at a later point i can call fwrite like loadedScript.fwrite

Ideally i would like to load the file and assign it's contents to the global table trough the C API.


I'm new to lua, and have no idea what to even look for to solve this.

Anyone have any ideas?