Jump to content
  • Advertisement
Sign in to follow this  
adam_o

Weird Translations

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
}
}


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!