Public Group

OpenGL how do I get my sprite to move up and down once

Recommended Posts

Posted (edited)

if I go back to studying up on c++  would that help? rutin how did  you get so good at programming?

Edited by phil67rpg

Share on other sites
7 minutes ago, phil67rpg said:

if I go back to studying up on c++  ﻿would that help﻿?

Are you really asking if learning the language that you are using is helpful?

Share on other sites
29 minutes ago, phil67rpg said:

is there a difference between using others code and reinventing the wheel?

You can use others code to learn someting new, but this only makes sense if you fully understand it afterwards.

To proof this, you should know how it works exactly, and be able to imagine program flow, run it in your mind. If you can't do that, even after years, then programming is not for you. (Most people can't do it)

Ofc. complex programs are too large to have it all in your mind. Still, the piece of code you actually work on must be understood in every detail, 100%. If it's only 99% it will never work. If you do not understand a tiny detail, this detail usually causes bugs or unexpected program behavior.

So if you copy paste code, trial and error until it behaves like you want, but you do not understand every single line, then you won't learn much. You should not move on right after it seems to work. You should only move on after you understand it, so next time you don't need to google for similar stuff again, and also you will be able to do necessary changes, extend functionality, etc.

There is no point in pasting somone else code and call it a day.

Share on other sites
Posted (edited)

is there any sites where I can learn c++  without pursuing games

Edited by phil67rpg

Share on other sites
13 minutes ago, phil67rpg said:

if I go back to studying up on c++  would that help? rutin how did  you get so good at programming?

I assume the very most programmers learned programming very quickly. Maybe a matter of weeks / months but not years.

Programming itself is not hard for us. Solving problems, learning required math, keeping large codebases maintable... that's hard, never the programming itself.

But many people just have not the ability to learn the very basics, like others who never can learn a musical instrument. They might learn to play a song given notation and long time practice, but they can not learn improvisation or composition. After all those years it certainly seems what you do is similar to this music example, and it might be just a waste of time to continue.

So why do you pursue, why not GameMaker for example?

Share on other sites
15 hours ago, phil67rpg said:

rutin how did  you get so good at programming?﻿

Don't know about Rutin, but I got good at it by focussing on deeply understanding every single line of code that I write or debug.

You get that by years of writing code all by yourself, without borrowing code from others, and by debugging the code yourself without asking others.

Share on other sites
Posted (edited)

Phil, write a little routine:

The program shall print a welcome message, then enter an endless loop (let's call it main loop ;-)). Inside the loop count from 0 to 10 and after reaching 10 down to 0 again in steps of 1. Output the value each iteration of the main loop. When down to 0 again, exit the main loop and print a good bye message.

That should not be problem. If you say it is too easy, we'll call you to show the solution. Don't ask, don't copy, don't look up. If you do, it's senseless.

Hope that's not totally devious ... boo at me if it is 🙂

Edited by Green_Baron

Share on other sites

I  am doing the exercises in my big c++ text

Share on other sites

in order to better understand jumping I have stubbed out some code which draws a parabolic curve. here is my screenshot https://imgur.com/pXIqF2C

here is my code

#include<freeglut.h>
#include<iostream>
#include<math.h>

using namespace std;

const float PI = 3.14159265;

float initialvelocity = 10.0f;
float thetaX = 0.0f;
float thetaY = 45.0f;
float gravity = 1.0f;

void drawCurve()
{
glPushMatrix();
glBegin(GL_POINTS);
for (float time = 0.0f; time < 15.0f; time += 0.1f)
{
glVertex3f(initialvelocity*time*cos(thetaX), initialvelocity*time*sin(thetaY*PI / 180.0f) + (-0.5f*gravity*time*time), 0.0f);
}
glEnd();
glPopMatrix();
}

void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
drawCurve();
glPopMatrix();
glutSwapBuffers();
}

void ChangeSize(GLsizei w, GLsizei h)
{
GLfloat aspectRatio;
if (h == 0)
h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho(-100.0, 100.0, -100.0 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);
else
glOrtho(-100.0*aspectRatio, 100.0*aspectRatio, -100.0, 100.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowPosition(400, 300);
glutInitWindowSize(800, 600);
glutCreateWindow("Parabola");
glutDisplayFunc(renderScene);
glutReshapeFunc(ChangeSize);
glutMainLoop();
}

Share on other sites

Okay, that's a good starting point. Make sure you completely understand each line before you move on to other things.

Next thing would be to replace curve drawing with image drawing.

Share on other sites
This topic is now closed to further replies.

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 23
• 37
• 16
• 75