# opengl game

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

## 49 Replies - 7569 Views - Last Post: 01 August 2018 - 02:18 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=411573&amp;s=72bc7e1b2f18a006b299ac62087b01b4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #31 pbivens85

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

## Re: opengl game

Posted 05 July 2018 - 05:14 PM

yes I meant Vo*t

### #32 pbivens85

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

## Re: opengl game

Posted 05 July 2018 - 06:41 PM

is this code appropriate for deriving delta time
```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;
}

```

### #33 pbivens85

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

## Re: opengl game

Posted 05 July 2018 - 07:08 PM

here id my code for using the position formula
```void delay()
{
float velocity = 20.0f, init_position = 0.0f;
static int prvMs = glutGet(GLUT_ELAPSED_TIME);
drawScene_bug_two(position, 10.0f);
const int curMs = glutGet(GLUT_ELAPSED_TIME);
const double dt = (curMs - prvMs) / 1000.0;
prvMs = curMs;
position = velocity*dt + init_position;
cout << position << endl;
}

```

### #34 andrewsw

Reputation: 6829
• Posts: 28,317
• Joined: 12-December 12

## Re: opengl game

Posted 06 July 2018 - 12:26 AM

"Is this code appropriate" ... what happens when you run it?

"here id my code" ... and...? What is your question?

The message is not getting through: provide a question each time; explain what you have tried and what happens with any code that you post.

### #35 modi123_1

• Suitor #2

Reputation: 15433
• Posts: 61,836
• Joined: 12-June 08

## Re: opengl game

Posted 06 July 2018 - 07:39 AM

Come on now.. don't turn this into your previous threads where it derails itself.

If you want to keep a journal of your progress then use the blog system.
If you have questions then ask them clearly.

### #36 pbivens85

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

## Re: opengl game

Posted 06 July 2018 - 03:48 PM

well ndc said I should use the position formula to move my sprites, I am using the position formula to move my sprite but it moves the sprite too quickly I want it to move slowly and one sprite width at a time.

### #37 pbivens85

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

## Re: opengl game

Posted 09 July 2018 - 07:11 PM

```void delay()
{
auto start = chrono::high_resolution_clock::now();
drawScene_bug_two(move_right, 10.0f);
auto end = chrono::high_resolution_clock::now();
chrono::duration<double> diff = end - start;
cout << diff.count() << endl;
}

```

well I have setup a timing loop but don't know how to implement it in moving my sprite.

### #38 pbivens85

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

## Re: opengl game

Posted 11 July 2018 - 03:22 PM

well when I run code in post #37 I get all zeros. I am trying to move my sprite using this timing loop.

### #39 andrewsw

Reputation: 6829
• Posts: 28,317
• Joined: 12-December 12

## Re: opengl game

Posted 13 July 2018 - 12:32 AM

@pbivens85 I have hidden your latest post. Unless you have a question to ask do not, as persistently told, post random updates. This forum is not a journal, blog or tweet.

"I want it to..." is not a question.

### #40 pbivens85

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

## Re: opengl game

Posted 14 July 2018 - 03:30 PM

```int time()
{
using namespace std::chrono;
auto now = high_resolution_clock::now();
auto millis = duration_cast<milliseconds>(now.time_since_epoch()).count();
cout << millis << endl;
return millis;
}

int refTime = time();

void move(int v)
{
move_right++;

if (move_right >= 9.0f)
{
move_right = 9.0f;
}
drawScene_bug_two(move_right, 10.0f);
glutPostRedisplay();
glutTimerFunc(1000, move, 0);
}

void drawScene() {
glClear(GL_COLOR_BUFFER_BIT);
bullet();
drawScene_bug_one(-2.0f, 10.0f);
if (time() - refTime > 1000)
{
move(0);
refTime += 1000;
}
coll_bug_one();
erase_sprite();
drawScene_ship_one();
glutSwapBuffers();
}

```

well I have done some research on the chrono function and have incorporated it into my game. I am able to print out the time since the last epoch in milliseconds. I am attempting to use the chrono function as a timing loop to move my sprites. is there anyway I can convert the high resolution clock into an integer without using the time since epoch command. as I have researched I don't think there is anyway to accomplish this.

### #41 pbivens85

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

## Re: opengl game

Posted 17 July 2018 - 06:32 PM

can I get some input on post #40

### #42 pbivens85

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

## Re: opengl game

Posted 24 July 2018 - 06:58 PM

well I am going to work on my game some more, is there anyway I can use the high resolution clock without using the time since epoch command?

### #43 pbivens85

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

## Re: opengl game

Posted 28 July 2018 - 07:14 PM

is post #40 too difficult?

### #44 ndc85430

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

Reputation: 984
• Posts: 3,879
• Joined: 13-June 14

## Re: opengl game

Posted 28 July 2018 - 10:59 PM

Why do you need to do everything with integers? Why not just use the standard library classes (i.e. std::time_point or std::duration as appropriate) for the calculations, since they support comparisons and addition/subtraction?

### #45 modi123_1

• Suitor #2

Reputation: 15433
• Posts: 61,836
• Joined: 12-June 08

## Re: opengl game

Posted 29 July 2018 - 08:21 AM

FYI - see what everyone else was suggesting:
https://www.opengl.o...833-move-sprite
https://www.gamedev....prite-movement/

pbivens85, on 28 July 2018 - 09:14 PM, said:

is post #40 too difficult?

I would wager folk have just departed the topic.