Concentrate 181 Report post Posted February 14, 2010 I am reading about Transformation. I googled it and found that it combines rotations, shears, scalings, and so on, all in one. Is gluLookAt(...) from glut, an example of an affine transformation that combines translation and rotations ? 0 Share this post Link to post Share on other sites
Halifax2 295 Report post Posted February 14, 2010 You are correct, gluLookAt is an example of an affine transformation that represents a translation and rotation to achieve the necessary viewing transformation. You can get a full definition of the function here. 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted February 14, 2010 Quote:Is gluLookAt(...) from glut, an example of an affine transformation thatcombines translation and rotations ?Yes, it is :)'Look-at' functions, in general, do the following:1. Build a rigid-body (i.e. rotation and translation only) transform given a position, a target position, and an up vector for reference.2. Invert the transform.The transform is inverted so that it can be used as a view/camera transform. A 'look-at' transform without the inversion is essentially an 'aim-at' transform, which can be used (for example) for billboard effects. 0 Share this post Link to post Share on other sites
Concentrate 181 Report post Posted February 14, 2010 You guys here at gamedev are so smart. I hope to achieve the statusof you guys one day. Thanks so much. 0 Share this post Link to post Share on other sites
Concentrate 181 Report post Posted February 14, 2010 Another question.So I am reading that the contraction and expansion in the horizontal direction is given by the matrix M = [k 0][0 1]and the contraction and expansion in the vertical direction is given byN = [1 0][0 k]So that essentially is scaling the object. How would I apply this to an object.Say I have a rectangle defined by the points: (0,1),(1,1),(0,1),(0,0). How would I scale the rectangle? Would I represent the rectangle by a matrix andmultiply it by either M or N? Can you show me an example please? Thanks. 0 Share this post Link to post Share on other sites
haegarr 7373 Report post Posted February 14, 2010 Vector math does not allow to multiply 2 matrices where the number of columns in the left matrix is different from the number of rows in the right matrix. So you cannot packetize an arbitrary (here 4) amount of vectors to build a matrix for a specific matrix product.Instead, you would multiply each point vector by the transformation matrix, so that you get the same amount of (transformed) vertices at the end. E.g.p_{i}' = M * p_{i} where i = 1,...,4Here M (i.e. the matrix on th left) has 2 columns, so the points p_{i} (the matrix on the right) needs to have 2 rows. Because the p_{i} has only 2 values, it is therefore a matrix with 2 rows and 1 column. Hence it is named a "column vector".You can also try the other way around:q_{i}' = q_{i} * M where i = 1,...,4Here M (i.e. the matrix on the right) has 2 rows, so q_{i} needs to have 2 columns by 1 row. Hence it is named a "row vector".This distinction is important due to matrix multiplication isn't commutative. The conversion between the 2 kinds is named "transposition" (a mirroring about the left-top to bottom-right diagonal). To be precise, the M's in the both formulas above are also not the same, because the one M must be the transpose of the other M.EDIT: Forgotten to say:The matrix product goes as follows: The value of the resulting matrix at column j and row k is the sum of all particular products of the values of the k-th row of the left argument matrix by the j-th column of the right argument matrix./EDITNow, using row vectors as an example, the products arep_{1}' = p_{1} * M = ( k * 0 + 0 * 1, 0 * 0 + 1 * 1 ) = ( 0, 1 )p_{2}' = p_{2} * M = ( k * 1 + 0 * 1, 0 * 1 + 1 * 1 ) = ( k, 1 )p_{3}' = p_{2} * M = ( k * 1 + 0 * 0, 0 * 1 + 1 * 0 ) = ( k, 0 ) // the OP has a faulty point herep_{4}' = p_{2} * M = ( k * 0 + 0 * 0, 0 * 0 + 1 * 0 ) = ( 0, 0 )so you can see a scaling in the horizontal direction.[Edited by - haegarr on February 14, 2010 2:09:04 AM] 0 Share this post Link to post Share on other sites
Concentrate 181 Report post Posted February 14, 2010 Oh, cool. Thanks for that sweet lesson, although I haven't grasped whatsome of the technical term means, at least I understand the main part.So its essentially is like multiply like so :Let M = [k 0][0 1]Let a Rectangle R be defined by the points, tl = (0,1), tr = (1,1), br = (0,1), bl = (0,0).Then the new set of points is calculated by the following multiplication, right?tl *= M;tr *= M;br *= M;bl *= M;where are represent t* and b* as a column vector, and M as a 2x2 matrix? 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted February 14, 2010 Quote:Then the new set of points is calculated by the following multiplication, right?tl *= M;tr *= M;br *= M;bl *= M;where are represent t* and b* as a column vector, and M as a 2x2 matrix?It depends on how the *= operator is implemented. Typically, v *= M would be equivalent to v = v * M, meaning that the vectors would be row vectors rather than column vectors. 0 Share this post Link to post Share on other sites
Concentrate 181 Report post Posted February 15, 2010 Oh. I see thank you. BTW, how would I appropriately define the coordinates of the rectangle? Would it be a good idea to define it as a matrices like R = [x y][x y+1][x+1 y+1][x+1 y]and then pass it onto a function called Matrix scaleHoritontal(const Matrix& m);where it does the necessary transformation. I'm just trying to visualize howone would implement one of these transformation, static methods, an Algorithclass, or what ? 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted February 15, 2010 Quote:Original post by ConcentrateOh. I see thank you. BTW, how would I appropriately define the coordinates of the rectangle? Would it be a good idea to define it as a matrices like R = [x y][x y+1][x+1 y+1][x+1 y]and then pass it onto a function called Matrix scaleHoritontal(const Matrix& m);where it does the necessary transformation. I'm just trying to visualize howone would implement one of these transformation, static methods, an Algorithclass, or what ?I'm not sure what the advantage of storing the coordinates in a matrix would be. Typically, you would just store the vertices in a container of some sort, and apply the transform matrix to each in turn (as described in haegarr's post).Note that a quad doesn't necessarily require special handling. A triangle has three vertices; a quad has four; an n-sided polygon might have more than four. Each of these shapes (and many others) can be represented in exactly the same way: as a collection of vertices and (optionally) connectivity information (e.g. indices).There are occasions where it may be advantageous to use a custom data structure for a particular type of shape, but in general you should think of geometric transformations as operating on a sequence of vertices, without regard for what shape they happen to represent. In other words, the function that applies the transform doesn't care (and doesn't even need to know) that the vertices it's working with represent a quad. 0 Share this post Link to post Share on other sites
Concentrate 181 Report post Posted February 15, 2010 Oh I see, but would I still need to know how many vertices the polygon hasper a face? 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted February 15, 2010 Quote:Original post by ConcentrateOh I see, but would I still need to know how many vertices the polygon hasper a face?I think that really depends on what problem you're trying to solve. There are many possible scenarios here - submitting geometry to a graphics API such as OpenGL or Direct3D, transforming geometry for the purpose of collision detection, manipulating geometry in a level editor or modeling program, etc. Each of these cases has different requirements, and you'd probably do things differently in each case.Another way to answer the question would be, you'll know once you start writing the code. If you're writing the code and you reach a point in the logic where it's necessary to know how many vertices the polygon has, then yes, you need to know how many vertices the polygon has :)So is there a particular problem you're trying to solve? Or are you just trying to gain a better understanding of geometric transforms in general? 0 Share this post Link to post Share on other sites
Concentrate 181 Report post Posted February 15, 2010 Thank jyk. There is no particular problem I am trying to solve. 0 Share this post Link to post Share on other sites