Weird Translations

Started by
17 comments, last by adam_o 17 years, 4 months ago
So I set up a program using C++ (cocoa) and OpenGL and told it to translate some stuff for me. I would press w to translate one way and x to translate another. I told it to increment these translations by 0.1 and whenever I get past 0.3 or -0.3, it will keep getting smaller or bigger until it goes off the screen, no matter which one I press. File is given below, stats in my signature. http://idisk.mac.com/adam_o/weird_translations.cpp
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
Advertisement
Your source file is blocked. (SC_AUTHORIZATION_REQUIRED!!!)
Quote:Original post by Omega147
Your source file is blocked. (SC_AUTHORIZATION_REQUIRED!!!)

Hmm... I don't know what that is... it worked on my computer, but it might just be in my keychain... I'm still learning how to work this dotmac stuff... will post when it's updated...
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
You can just paste your code directly into your post (use [source] tags to preserve formatting).
Quote:Original post by jyk
You can just paste your code directly into your post (use tags to preserve formatting).


Will that work for 100+ lines of code?

EDIT: Try this:

http://idisk.mac.com/adam_o/here/weird_translations.cpp
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
same issue here, need auth...
--X
Quote:Original post by adam_o
Quote:Original post by jyk
You can just paste your code directly into your post (use tags to preserve formatting).


Will that work for 100+ lines of code?

EDIT: Try this:

http://idisk.mac.com/adam_o/here/weird_translations.cpp

Still asks for a username and password.

You could put your code in here, just be sure to use source tags like this:

Code goes here!
(edit my post to see the use for source tags)

Otherwise, your 100+ lines would stretch on for a while, cluttering the thread. Making the actual file available is better when you have that much source to show, so maybe just find a different host server to put it up somewhere or something.
Here goes nothing!
#include <GLUT/glut.h>using namespace std;GLfloat ztrans;void draw();void init();void kybrd(unsigned char key, int x, int y);int main(int argc, char** argv){	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);	glutInitWindowSize(500, 500);	glutInitWindowPosition(100, 100);	glutCreateWindow("Weird Translations");	init();	glutKeyboardFunc(kybrd);	glutDisplayFunc(draw);	glutMainLoop();	return 0;}void drawString(GLint x, GLint y, const char *string) {	int i;	glPushAttrib(GL_TRANSFORM_BIT | GL_CURRENT_BIT);	glMatrixMode(GL_PROJECTION);	glPushMatrix();	glLoadIdentity();	glOrtho(0, 640, 0, 480, -10.0, 10.0);	glMatrixMode(GL_MODELVIEW);	glPushMatrix();	glLoadIdentity();	glColor4f(1.0, 1.0, 1.0, 1.0);	glRasterPos2i(x, y);	int len = (int)strlen(string);	for ( i = 0; i < len; i++) 	{		glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string);	}	glPopMatrix();	glMatrixMode(GL_PROJECTION);	glPopMatrix();	glPopAttrib();}void draw(){	char infostring[1024];	glTranslatef(0.0, 0.0, ztrans);	glClear(GL_COLOR_BUFFER_BIT);	glBegin(GL_QUADS);	glVertex3f(0.0, 0.0, -5.0);	glVertex3f(1.0, 0.0, -5.0);	glVertex3f(1.0, 1.0, -5.0);	glVertex3f(0.0, 1.0, -5.0);	glEnd();	snprintf(infostring, 1023, "Keys are 'w', 'x' or ESC to exit, ztrans = %f", ztrans);	drawString(10, 10, infostring);	glFlush();}void init(){	glClearColor(0.0, 0.0, 0.0, 0.0);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluPerspective(100.0, 10/10, 0.001, 10000.0);	glMatrixMode(GL_MODELVIEW);}void kybrd(unsigned char key, int x, int y){	switch (key)	{		case 'w':		{			ztrans += 0.1;			glutPostRedisplay();			break;		}		case 'x':		{			ztrans -= 0.1;			glutPostRedisplay();			break;		}		case 27:		{			exit(0);			return;		}		default: return;	}}

_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
You realize that in one second you can have over 60 frames and that would lead to moving at least 6 units per second. My advice would be to set a breaker after like 50 loops in the draw section and see what your ztrans value is. If it seems right, then its your translation, otherwise it might just be your actual ztrans, which is whats wrong most of the time with mine.
There are a couple of things in your code I'm not sure about, but I would try adding a call to glLoadIdentity() before the line:
glTranslatef(0.0, 0.0, ztrans);
As it is now, you're accumulating the translation from frame to frame in the OpenGL modelview matrix, which is not what you want.

This topic is closed to new replies.

Advertisement