# thewhiteaussie

Member

11

157 Neutral

• Rank
Member
1. ## Is the concatenation of a VQS with its inverse commutative?

SOLVED.   Solution was to ensure all quaternions were normalized, thus representing rotations.
2. ## Is the concatenation of a VQS with its inverse commutative?

Ok good idea. Here's an example that might help. Incidentally, the issue it seems appears to be with the Inverse(VQS) function. Here's a test case:   T = [(-3.2, 1.6, -10.3) , (-0.52, 0.68, 0.49, 0.32) , 2]   Inverse( Inverse(T) ) = [(-4.0, 2.5, -9.9) , (-0.52, 0.68, 0.49, 0.32) , 2]   Inverse( Inverse(T) ) should return T. The scalar and quaternion components are correct, however the translation vector is off. It looks like the method to find the inverse translation component might be incorrect.
3. ## Is the concatenation of a VQS with its inverse commutative?

Quaternion concatenation is noncommutative. That is   qa * qb  ?  qb * qa   However   q-1 * q = q * q-1 = Iq   where q-1 is the inverse of q and Iq is the identity quaternion. VQS concatenation is also noncommutative:   TA_B  * TB_C  ?   TB_C * TA_B   Where TA_B represents a VQS transformation. Now, we find the inverse of TA_B like so:   TA_B-1 = TB_A   My question is, is the concatenation of a VQS with its inverse commutative? Ie, is the following statement correct?   TA_B * TB_A = TB_A * TA_B = IVQS   Where IVQS  is the identity VQS. With the implementation I’m using I’m finding   T -1 * T   =   IVQS, whereas T * T -1   ?   IVQS   This seems incorrect; both sould return IVQS.     EDIT:   Here is the implementation of VQS Inverse and concatenation functions I'm using: //-------------------------------------------------------------------------------- // Concatenation //-------------------------------------------------------------------------------- VQS VQS::operator*(const VQS& rhs) const { VQS result; //Combine translation vectors result.v = q.Rotate(rhs.v) * s + v; //Combine quaternions result.q = q * rhs.q; //Combine scales result.s = s * rhs.s; //Return result return result; } //End: VQS::operator*() //-------------------------------------------------------------------------------- // Returns inverse VQS //-------------------------------------------------------------------------------- VQS Inverse(const VQS& other) { VQS temp; //Inverse scale temp.s = 1.0f / other.s; //Inverse quaternion temp.q = Inverse(other.q); //Inverse vector temp.v = temp.q.Rotate(-other.v) * temp.s; return temp; } //End: Inverse()
4. ## World to Camera Transformation using Quaternions

Yes you're right! Also it seems like more work to use Quaternions for the final World to Camera transform. I might just stick with matrices.
5. ## World to Camera Transformation using Quaternions

I have a question regarding quaternions and rotations.   Let the quaternion q(w, x, y, z) represent the orientation of a camera in world space. I use a UVN camera system where u = right vector, v = up vector and n = forward vector. With zero rotation the camera aligns with the world basis vectors (x, y, z) like so:   u aligns with +x v aligns with +z n aligns with +y   My question is how do I construct a quaternion that rotates objects from the RH coordinate system of the world space to a LH coordinate system with the following alignments:   u aligns with +x v aligns with +y n aligns with +z   Previously I've use the matrix   [ ux   vx   nx ] [ uy   vy   ny ] [ uz   vz   nz ]   however want to switch to a completely quaternion based system.   I suspect I'll need q-1. This rotates objects into camera space, preserving handedness. To switch alignments I suspect I'll need to swap terms in the quaternion.   Thanks.
6. ## Triangle rasterization troubles

Thanks guys. After much experimentation, the problem was with rounding errors. I have since switch to using a fixed point number representation for greater accuracy and have solved the issue, pretty much as AB suggested.   Also, Krypt0n you migh be right about the error introduced by incrementing xs and xe each iteration, I'll check it out.
7. ## Triangle rasterization troubles

I'm trying to write a couple of functions to draw (filled) flat-top and flat-bottom triangles. For the large part they work however cracks are still sometimes seen between adjacent triangles. I use an interpolating technique whereby I raster the triangle line by line, calculating the new left and right limits at each step. Much of this is explained in the code, but here is the general idea (for a flat bottom): 1) Find dy (height) 2) Find dy/dx (slope) from the top point to each bottom point 3) Move to the starting row ( floor(top point) ), and find initial x-start and x-end coordinates 4) Interpolate down the triangle I should note that cracks are only seen between triangles that join at the sides, not top/bottom joins. I've been at this so long I don't know what to try anymore. I think the logic is solid, maybe any cracks are due to floating point error. I'd really appreciate some feedback. [source lang="cpp"]typedef unsigned int uint32; Line(uint32 y, uint32 x_left, uint32 x_right); //Draws a horizontal line at these coords struct vector2 { float x,y; }; //-------------------------------------------------------------------------------- // Draws a flat bottom triangle from top to bottom //-------------------------------------------------------------------------------- void Draw_Bottom_Tri_SOLID(Vector2 p0, Vector2 p1, Vector2 p2) { //Point order: //Bottom left: p0 //Bottom right: p1 //Top point: p2 //calculate dy float dy = p2.y - p0.y; //dx/dy for the left and right edges float dxdy_left = (p0.x - p2.x)/dy; float dxdy_right = (p1.x - p2.x)/dy; //Since we start the raster process at floor(p2.y) //we need to shift the x start and x end postions along //by this factor: float y_bump = p2.y - floor(p2.y); //Initial start and end x values float xs = p2.x + dxdy_left*y_bump; //x left (start) float xe = p2.x + dxdy_right*y_bump; //x right (end) uint32 yb = uint32(p0.y) + 1; //y bottom, +1 for top left fill convention uint32 yt = uint32(p2.y); //y top, use casting instead of std::floor //Draw lines for (uint32 i = yt; i >= yb; i--) { //Set left and right limits, use casting instead of std::floor uint32 left = uint32(xs) + 1; //+1 for top left fill convention uint32 right = uint32(xe); //Draw line, can also be std::fill or simply a for loop. Line(i, left, right); //Increment limits xs += dxdy_left; xe += dxdy_right; } } //End: Draw_Bottom_Tri_SOLID() //-------------------------------------------------------------------------------- // Draws a flat top triangle from bottom to top //-------------------------------------------------------------------------------- void Draw_Top_Tri_SOLID(Vector2 p0, Vector2 p1, Vector2 p2) { //Point order: //Top left: p0 //Top right: p1 //Bottom point: p2 //calculate dy (height) float dy = p0.y - p2.y; //dx/dy for the left and right edges float dxdy_left = (p0.x - p2.x)/dy; float dxdy_right = (p1.x - p2.x)/dy; //Find shifting factor float y_bump = ceil(p2.y) - p2.y; //Initial start and end x values float xs = p2.x + dxdy_left*y_bump; //x left (start) float xe = p2.x + dxdy_right*y_bump; //x right (end) uint32 yb = uint32(p2.y) + 1; //y bottom, +1 for top left fill convention uint32 yt = uint32(p0.y) ; //y top //Draw lines for (uint32 i = yb; i <= yt; i++) { //Set left and right limits uint32 left = uint32(xs) + 1; //+1 for top left fill convention uint32 right = uint32(xe); //Draw line, can be std::fill or simply a for loop. Line(i, left, right); //Increment limits xs += dxdy_left; xe += dxdy_right; } } //End: Draw_Top_Tri_SOLID() [/source]
8. ## Clipping to frustum question.

Hello. I have a question regarding clipping a polygon against a view frustum. For simplicity, consider the case of clipping a triangle to a rectangle. The Sutherland-Hodgman algorithm achieves this by clipping the triangle to each side of the rectangle successively. A new polygon must be created and stored after each clipping phase, to be sent on to be clipped against the next edge of the rectangle. My question is this: can we take advantage of the recursive nature of the algorithm to avoid storing these (four) temporary polygons? Once a vertex has been clipped to one side, can we send it straight to the next clipping phase? Below is the logic I have developed thus far. It processes each line of the triangle separately by clipping against the boundaries in the following order: [source lang="cpp"] Top -> Bottom -> Left -> Right -> Output [/source] Points that pass the final clipping phase (Right) are added to the output polygon. It is currently incorrect. It cannot 'wrap' a triangle around a corner of the rectangle. I think I'm on the right track though. I would love some feedback [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Here are the functions in pseudocode: [source lang="cpp"] //Clip polygon master function. The clipping rectangle has previously been defined. void ClipPolygon(point p0, point p1, point p2) { ClipToTop(p0, p1); ClipToTop(p1, p2); ClipToTop(p2, p0); } //-------------------------------------------------------------------------------- // Clip to top //-------------------------------------------------------------------------------- ClipToTop(point previous, point current) { if (/*previous and current are both inside*/) { ClipToBottom(previous,current); return; } if (/*previous inside and current outside*/) { //find intersection: 'intersect' ClipToBottom(previous,intersect); return; } //If both outside: do nothing if (/*previous outside and current inside*/) { //find intersection: 'intersect' ClipToBottom(previous,intersect); ClipToBottom(intersect,current); return; } } //-------------------------------------------------------------------------------- // Clip to bottom //-------------------------------------------------------------------------------- ClipToBottom(point previous, point current) { if (/*previous and current are both inside*/) { ClipToLeft(previous,current); return; } if (/*previous inside and current outside*/) { //find intersection: 'intersect' ClipToLeft(previous,intersect); return; } //If both outside: do nothing if (/*previous outside and current inside*/) { //find intersection: 'intersect' ClipToLeft(previous,intersect); ClipToLeft(intersect,current); return; } } //-------------------------------------------------------------------------------- // Clip to left //-------------------------------------------------------------------------------- ClipToLeft(point previous, point current) { if (/*previous and current are both inside*/) { ClipToRight(previous,current); return; } if (/*previous inside and current outside*/) { //find intersection: 'intersect' ClipToRight(previous,intersect); return; } //If both outside: do nothing if (/*previous outside and current inside*/) { //find intersection: 'intersect' ClipToRight(previous,intersect); ClipToRight(intersect,current); return; } } //-------------------------------------------------------------------------------- // Clip to Right //-------------------------------------------------------------------------------- ClipToRight(point previous, point current) { if (/*previous and current are both inside*/) { //Add current to output polygon } if (/*previous inside and current outside*/) { //find intersection: 'intersect' //Add intersect to output polygon } //If both outside: do nothing if (/*previous outside and current inside*/) { //find intersection: 'intersect' //Add intersect to output polygon //Add current to output polygon } } [/source]
9. ## Q: Fast and simple way to store/manipulate pixels?

Ok thanks, I think [CODE] reinterpret_cast [/CODE] will prove useful. Also I think you're righ eppo. Working with UCHAR data seems to have a few limitations.
10. ## Q: Fast and simple way to store/manipulate pixels?

Hodgman: Thanks I think I get it. I'm unfamiliar with static_cast but it looks like you can read a section of memory as a different data type. I'm going to check it out. Ashaman73: I realise that however 1) I'm still fairly inexperienced, and 2) for the environments I'm rendering, the cpu should be enough I think.
11. ## Q: Fast and simple way to store/manipulate pixels?

Hello. I'm currently experimenting with writing simple 3D engines and so far [url="http://www.youtube.com/watch?v=aC7I9fFUkF0"]isn't going too bad[/url]. I'm coding with C++ and using SDL. So far I've been using SDL's functions to generate surfaces and to manipulate pixels. However I would like to write my own class to represent surfaces, like so: [source lang="cpp"]struct Color { Uint8 red; Uint8 green; Uint8 blue; Uint8 alpha; }; //Create a 1024*768 surface Color* Screen = new Color[1024*768];[/source] I want to achieve easy and fast color manipulation, while removing much of the dependency of a specific rendering API. Using the above method I would simply need to convert 'Screen' to the Uint32 format SDL needs at the end of the game loop. I guess I'd like to hear some thoughts on this idea before I proceed. I'm concerned this might not end up being a very efficient way of doing things, however at present it should be faster than converting a Uint32 pixel format to RGB data and then back again (what I'm doing now); I'm only doing one conversion during runtime. Also, is there a common, generic way to represent images that isn't API specific? Frank