opengl game

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

49 Replies - 6816 Views - Last Post: 01 August 2018 - 02:18 PM Rate Topic: -----

#16 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 28 June 2018 - 01:53 PM

void move(int v)
{
	move_right++;

	glutTimerFunc(10000, move, 0);

	drawScene_bug_two(move_right, 10.0f);

	if (move_right >= 8.0f)
	{
		move_right = 8.0f;
	}
}

void drawScene() {
	glClear(GL_COLOR_BUFFER_BIT);
	bullet();
	drawScene_bug_one(-2.0f, 10.0f);
	move(0);
	coll_bug_one();
	erase_sprite();
	drawScene_ship_one();
	glutSwapBuffers();
}


I am trying to move a bug right but at a slower speed, it moves right but at a high rate of speed. I am trying to use glutTimerFunc to slow down the speed.
Was This Post Helpful? 0
  • +
  • -

#17 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: opengl game

Posted 28 June 2018 - 01:58 PM

Why wouldn't you change the constant amount of speed it moves instead?
Was This Post Helpful? 0
  • +
  • -

#18 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 28 June 2018 - 02:01 PM

are you referring to the move_right variable?
Was This Post Helpful? 0
  • +
  • -

#19 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: opengl game

Posted 28 June 2018 - 02:03 PM

If that's what you are using to have the sprite move right, then yes.
Was This Post Helpful? 0
  • +
  • -

#20 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 28 June 2018 - 02:09 PM

I have tried using the move_right variable and it does slow the sprite but I want it to move the sprite right by one width of the sprite at a time, I want it to skip to the right. just like in space invaders.
Was This Post Helpful? 0
  • +
  • -

#21 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: opengl game

Posted 28 June 2018 - 02:15 PM

Fair enough, then that wouldn't do.

I would think about using 'variable time' and not fixed time.

Track glutGet(GLUT_ELAPSED_TIME) in a variable and compare it to make 'delta time'.. then use that to figure in when your sprite needs to move. Most of the OpenGL books discuss it.

Nifty read on it:
https://gamedev.stac...iable-time-step
https://books.google...%20time&f=false
Was This Post Helpful? 0
  • +
  • -

#22 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 28 June 2018 - 06:15 PM

ok I will do some research on GLUT_ELAPSED_TIME, I have also heard of this before.
Was This Post Helpful? 0
  • +
  • -

#23 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 28 June 2018 - 08:17 PM

well before I get into GLUT_ELAPSED_TIME I have found out that the following code draws a sprite right once but then accelerates to the edge of the screen. I think the problem is in the move_right++ incrementor.
void move(int v)
{
	move_right++;
	if (move_right >= 9.0f)
	{
		move_right = 9.0f;
	}
	drawScene_bug_two(move_right, 10.0f);
	glutPostRedisplay();
}

void drawScene() {
	glClear(GL_COLOR_BUFFER_BIT);
	bullet();
	drawScene_bug_one(-2.0f, 10.0f);
	delay();
	glutTimerFunc(1000, move, 0);
	coll_bug_one();
	erase_sprite();
	drawScene_ship_one();
	glutSwapBuffers();
}


Was This Post Helpful? 0
  • +
  • -

#24 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 30 June 2018 - 02:50 PM

void delay()
{
	static int prvMs = glutGet(GLUT_ELAPSED_TIME);
	const int curMs = glutGet(GLUT_ELAPSED_TIME);
	const double dt = (curMs - prvMs) / 1000.0;
	prvMs = curMs;
//	cout << dt << endl;
}


well I am able to calculate delta time but I am unsure of how to apply it to sprite movement.
well modi123 do you have any input that could help me?
I am going to work on this problem more.

This post has been edited by pbivens85: 30 June 2018 - 06:25 PM

Was This Post Helpful? 0
  • +
  • -

#25 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 957
  • View blog
  • Posts: 3,790
  • Joined: 13-June 14

Re: opengl game

Posted 30 June 2018 - 10:34 PM

You likely need to give more context, but this seems like basic kinematics really:

Let x(t) be the position of the object at time t and v be its speed. Then, v * dt is the distance travelled in time dt, so the new position (at time t + dt) is just given by

x(t + dt) = x(t) + v * dt

If you're dealing with more than one dimension, then you apply this to each of the components of the position vector (using the corresponding velocity component, of course).

Clearly, this only works if the velocity is constant. If you have constant acceleration, the expressions are different. It is left as an exercise for you to find those, should you need them.

This post has been edited by ndc85430: 01 July 2018 - 12:32 PM

Was This Post Helpful? 1
  • +
  • -

#26 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 01 July 2018 - 02:45 PM

I have not seen this equation since I took physics in college.
Was This Post Helpful? 0
  • +
  • -

#27 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 04 July 2018 - 01:08 PM

well I did some research on this position formula, but I am unsure of how to implement this formula in my code. modi said I should post in my thread. thanks ndc for the help.
Was This Post Helpful? 0
  • +
  • -

#28 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: opengl game

Posted 04 July 2018 - 05:43 PM

I have looked up the position formula and found the formula: x(t)=Vo(t)+Xo where Vo is the initial velocity and Xo is the initial position. and t is the time. this is for a zero acceleration. I am going to work on the code for this formula. also x(t) is the current position. I am unsure of how to implement the t (time) factor.
Was This Post Helpful? 0
  • +
  • -

#29 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 957
  • View blog
  • Posts: 3,790
  • Joined: 13-June 14

Re: opengl game

Posted 04 July 2018 - 10:30 PM

Yes, that's exactly what I said above. Well, your notation is confusing. You've written "Vo(t)", which makes it look like a function (like "x(t)") and that means your equation is dimensionally incorrect: x(t) has dimensions of length and so does X0, but Vo(t) has dimensions of length/time. Presumably you really meant Vot (i.e. Vo * t).

t should be the time between the start and end points of your motion, which you're already calculating (though you're giving it a different name).

This post has been edited by ndc85430: 04 July 2018 - 10:57 PM

Was This Post Helpful? 0
  • +
  • -

#30 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6700
  • View blog
  • Posts: 27,542
  • Joined: 12-December 12

Re: opengl game

Posted 05 July 2018 - 12:36 AM

"I have not seen this", "I am unsure of how to", "I am going to work on". None of these are questions, just random tweet-like statements.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4