# ajas95

Member

776

767 Good

• Rank

• Interests
Programming

## Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

1. ## Towers 'n Trolls (free-to-play on Android)

We just got a main Feature of the Week from Google Play, and the #1 staff pick, w00t! (and #2 for tablets) https://play.google.com/store/apps
2. ## Towers 'n Trolls (free-to-play on Android)

So a friend and I (Emeyex, another long-time gamedev.net poster) made this game-- he wrote the engine and gameplay, and I wrote the Android port, and my 2 other friends made the levels and art. It's a fast-paced and very pretty Tower Defense game, and free to play! Download it and let me know what you think! https://play.google.....android.ftdjni
3. ## Translating a point between Cartesian Coord Systems

First you need to construct the world matrix for your "UCS" transform. You need the Z axis which can be found by taking the cross of X and Y, and then arranging them as columns in a 4x4 matrix (with translation in the last column). so then you have: 0.9644 0.8617 -0.029 438.8587 0.2481 0.5029 0.0131 180.6440 0.0913 0.0679 0.2712 0.0 0.0000 0.0000 0.0000 1.0 You're looking to transform the point in world-space by the INVERSE of this matrix to go into UCS space. To invert a 4x4 matrix that has only rotation and translation, you transpose the 3x3 portion which is the rotation, and then multiply the negative translation by that transposed 3x3 matrix and those combine to yield the inverse. So you multiply your point by the resulting matrix: 0.9644 0.2481 0.0913 -468.053 495.835 0.8617 0.5029 0.0679 -469.010 * 203.1717 -.0290 0.0132 0.2712 10.374 43.2574 0.0000 0.0000 0.0000 1.0 1.0 and that will give the point in the local coordinate system.
4. ## Convert UV coord to 3d position

Okay, I think I know how to do this. Roughly, first treat the UVs of the vertices as a 2d space, and find the barycentric coords of the input UV. This gives an output UV s.t. v0.uv + v1.uv*outU + v2.uv*outV = inUV then outUV can be applied to the vertices positions like: outPos = v0.xyz + v1.xyz*outU + v2.xyz*outV and that's that. So just need the 2d triangle barycentric calculation.
5. ## Convert UV coord to 3d position

So, I can't seem to figure this one out for some reason. I'm sure the answer involves solving a simple determinant or something similar to moller-trumbore ray/tri intersection but in reverse! Anyway, say I have a triangle and the three verts have x,y,z position and u,v coords. Now say I have an input UV coordinate, how do I find the point in 3d space in the plane of the triangle for that UV coordinate, given the UV space defined by the verts? Thanks for any help.
6. ## Freshman in college (advice)

Haha! I will agree with trzy wrt Ironpoint (though Ironpoint has some very true things to say depending on who you are). It comes down to this... some problems are important to you, you work through the night and drain every ounce of your brain to solve them, and you work until you're convinced that every human on earth, if placed in your shoes, would quit. And that makes you go further until you have it working... or there is tomorrow day and night if you are lucky! Or... you can choose another path. It's a pretty clear split that lays at your feet.
7. ## PS3 (going down???)

I know one thing: I bought my sister a PS2 for xmas because... it's hard to say exactly. There are so many sweet games, you don't need HD, they're all priced reasonably, the slimline is so small and sexy, plays DVDs, networking built in, it's pretty cheap, more games coming. In some respects like the Wii, except half the cost. There are more games, better games, at less than half the price. Folks who enjoy their XBox 360 seem to think that Halo 3 will be a huge attraction to people beyond those that own Halo 2 and Halo 1... and who don't already own an XBox 360. That's pretty unlikely. Next-gen all around has exhausted its current pricing.
8. ## Happy Valentine's Day!

yom tov rebbe valenstein. I've learned this: At least write a card. You have feelings and you can write and it costs nothing. Seriously, if you can't write a good card once a year, you probably don't deserve to be loved ;) Hey, someone has to say it.
9. ## avoiding virtual functions

Hi ToohrVyk, You should understand that while "last-gen" consoles had a piddly, measly I-Cache size of 16kb, after 6 years of technological breakthroughs our monster-sized "Next-Gen" I-cache is a whopping 32kb (shared between 2 hardware threads, just to show it is a really poor improvement). And the cache-line is quadrupled from 32 bytes to 128. So grabbing a few bytes here and there randomly, like accesses into vtables, or even when the vtable pointer itself may be unfortunately positioned... it can be really bad. There just isn't enough wayism in the cache to cover the wayivity of tendrils thrown out from virtual functions. Still, toohrvyk, I have myself written almost exactly your code into games that have shipped on three platforms! I felt really guilty at the time, it looks like a huge hack... But the client just includes your header, and doesn't even realize it's getting the platform-specific version rather than just an interface. And just for debugging purposes, a flip in the typedef gives the "reference version" platform-agnostic C code to test against the 3000 lines of vector assembly version. I'm glad someone else thought of the same solution to a weird problem. [Edited by - ajas95 on January 30, 2007 2:22:15 AM]
10. ## Tetris Programming?

Hi Strass150, Tetris is a good place to start. At least, it was my first game of any substance because it was my favorite game in high school (we're talking 13h days... :) Anyway, here is kind of the order I did things. 1) draw one brick square, solid color. const int BRICK_WIDTH = 9; const int BRICK_HEIGHT = 10; void drawBrick( int xCoordinate, int yCoordinate, int color ) { for( int y = 0; y < BRICK_HEIGHT; y++ ) for( int x = 0; x < BRICK_WIDTH; x++ ) PlotPixel(x,y,color); } 2) draw a darker line near the left and bottom to look more 3d. 3) draw 4 such bricks in a shape like a tetris block, positioning by hand. 4) draw 4 bricks based on a little piece of C code like int brickPos[4][2] = { {0,0}, {1,0}, {1,0}, {1,1} }; // square block for( brickIdx = 0; brickIdx < 4; brickIdx++ ) { drawBrick( brickPos[brickIdx][0] * BRICK_WIDTH, brickPos[brickIdx][1] * BRICK_HEIGHT, YELLOW ); } 5) rotate a block through its positions: // L-block in all four rotations int brickPos[4][4][2] = { { {0,0}, {0,1}, {1,1}, {2,1} }, { {1,0}, {1,1}, {0,2}, {1,2} }, { {0,0}, {1,0}, {2,0}, {2,1} }, { {0,0}, {1,0}, {0,1}, {0,2} }, }; int rotationIdx = 2; // rotated twice for( brickIdx = 0; brickIdx < 4; brickIdx++ ) { drawBrick( brickPos[rotationIdx][brickIdx][0] * BRICK_WIDTH, brickPos[rotationIdx][brickIdx][1] * BRICK_HEIGHT, YELLOW ); } 6) Same for all seven blocks. 7) Position a block within the well. int rotationIdx = 2; // rotated twice int wellPos[2] = { 3, 5 }; // three blocks over, 5 down for( brickIdx = 0; brickIdx < 4; brickIdx++ ) { drawBrick( (wellPos[0] + brickPos[rotationIdx][brickIdx][0]) * BRICK_WIDTH, (wellPos[1] + brickPos[rotationIdx][brickIdx][1]) * BRICK_HEIGHT, YELLOW ); } 8) Actual game is now starting... when a block lands, assign its brick positions into the well. const int WELL_WIDTH = 10; const int WELL_HEIGHT = 23; int Well[WELL_HEIGHT][WELL_WIDTH] = { {0} }; void brickLanded( int brickPos[4][2], int wellPos[2], int color ) { for( brickIdx = 0; brickIdx < 4; brickIdx++ ) { Well[wellPos[1] + brickPos[brickIdx][1]] // y coordinate in well [wellPos[0] + brickPos[brickIdx][0]] // x coordinate in well = color; } } 9) Check to see if a block can move down. bool canMoveToPos( int brickPos[4][2], int wellPos[2] ) { for( brickIdx = 0; brickIdx < 4; brickIdx++ ) { if( Well[wellPos[1] + brickPos[brickIdx][1]] // y coordinate in well [wellPos[0] + brickPos[brickIdx][0]] // x coordinate in well != 0 ) return false; // this brick would collide with one already in well. } return true; // no collisions, so new position is okay. } bool canMoveDown( int brickPos[4][2], int currentWellPos[2] ) { int newWellPos[2]; int newWellPos[0] = currentWellPos[0]; // x-coordinate the same int newWellPos[1] = currentWellPos[1] + 1; // y-coordinate bumped down one return canMoveToPos( brickPos, newWellPos ); } 10) Check for rotations also. bool canRotate( int brickPos[4][4][2], int currentRotation, int currentWellPos[2] ) { return canMoveToPos( brickPos[(currentRotation 1)%4], currentWellPos ); } 11) ..........
11. ## Accessing SSE (__m128) vector's fields

I'll amend what I wrote by mentioning that the compiler can use the *ss form of instructions to carry out the fp math on your vector component. I'm pretty sure it doesn't, but... It could generate a shufps or movhlps to grab your component into the SSE prefered slot, manipulate it via addss mulss etc, and shufps it back into the original vector. It all stays in SSE registers so no penalties I mentioned before apply, and it would be much faster. If I see a compiler do this... maybe that day I will stop writing assembly :)

13. ## aligned new class array operator

Hi, this page may be helpful to you. Particularly: "The sizeof value for any structure is the offset of the final member, plus that member's size, rounded up to the nearest multiple of the largest member alignment value or the whole structure alignment value, whichever is greater." This leads me to believe that by declspec(align())ing your class will change its size, so as to be a multiple of your alignment... which should make your array sizing work implicitly. As far as reasons why a structure is not an expected size... you know that vtable may not be 4 bytes (in cases of multiple virtual inheritance, for instance), and that if RTTI is turned on, that will get some bytes too. I suspect RTTI may well be your problem.
14. ## Why the aversion to all things "C"?

Wow, such viciousness against C. I've tried the various streams for file I/O, but I always make it back to good old ftell, fseek, fwrite for exporting binary game data. Also the printf-style functions are more convenient, IMO. If I want to only output 2 decimals of precision or properly display a pointer address, it's just %4.2f or %.8x, done. I'm not saying this because of an affinity for any language... simply what I've found most convenient in the real world. Someone made the point that NULL-terminated strings are stupid. Well that's true without a doubt. std::string is no picnic, though. At least for internal use, those str* functions are pretty succinct and even have range-checked versions. Seriously, what is the best way to implement strtok with std::string?
15. ## Sampling Points on a Triangle?

for 2 positive random values u,v where u + v <= 1.0 : P = v1 + (v2-v1)*u + (v3-v1)*v