Heya guys, I've been busy! I've been cranking out simple 3D C++ apps that my girlfriend's kids love. I made a pong clone and now I'm working on a maze game, etc etc. Lots of fun.
Here's the trouble! 3D graphics = math. I'm a better programmer than arithmetician.
How can I reduce/simplify this?Code:((14 - (int)(13.8 - ((float)y / 35.217)))*50)+((int)(-25.0 + ((float)x / 34.7)) + 25)
What it does? Takes the x and y coordinates from OpenGL's "glutMotionFunc" - and translates them to object space coordinates some -30Z units in the distance. The x and y are serialized into a linear one dimensional array of 1,400 3-float structures. This array can be saved and loaded from disk like lightning, which is hot... but then getting it back into X and Y (adjusted from two positive coordinates (gotten by a modulus 50, and a subsequent divide 50) into a 0,0 signed coored.... omg... I digress.
I can always post some source. I'm NOT gonna do this way next time, and I learned alot. But man, 3 days to get this solution. The key was finally inverting the Y coord at the end of the process. Anyhow... relevant code for the sick freaks like me:
Code Produced here: [Edited, wrecked, I'm tired, sorry]
And here's the final, compact, Linus Torvalds would shoot me, over simplification, noob, product:Code:static void motion(int x, int y) { cursorPosX = -25.0 + ((float)x / 34.7); cursorPosY = 13.8 - ((float)y / 35.217); clog << "Window Coordinates in Pixels with top left origin: "; clog << "x: " << x << " y: " << y << endl; clog << "Screen space coordinates with center origin: "; clog << "x: " << cursorPosX << " y: " << cursorPosY << endl; clog << "Formulation board coordinates from top-left: "; clog << "x:" << (int)cursorPosX + 25 << " y: " << 14 - (int)cursorPosY << endl; boardX = (int)cursorPosX + 25; boardY = 14 - (int)cursorPosY; int square = (boardY*50)+boardX; cout << boardX << " " << boardY << " " << square << " \\ " << (square % 50) << " " << (square / 50 ) << " [" << (square % 50)-25 << " " << -((square / 50 )-14) << "]" << endl; board[square] = colorTable(currentColor); }
Which is why I need help reducing that badboy on the last line.Code:static void motion(int x, int y) { cursorPosX = (-25.0 + ((float)x / 34.7)); cursorPosY = (13.8 - ((float)y / 35.217)); board[((14 - (int)(13.8 - ((float)y / 35.217)))*50)+((int)(-25.0 + ((float)x / 34.7)) + 25)] = colorTable(currentColor); }
Thank you if any spare time or effort. You gurus inspire me.
M. Richard Tober



LinkBack URL
About LinkBacks



