Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Making rotations visually happen within a do loop?

Author
Message
fuzz one
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 19th May 2006 00:59
inside a do loop, i dont seem to have any control on rotations.

like let's say my object is at 0,0,0. What if i want to rotate the object like : zrotate 1,35

and be able to see the rotation occur instead of it going from 0 to 35 instantly.

Like lets say i have an elevator, i want to see this elevator move up and down? How do i actually make the movement visible?

i'm just having trouble thinking this logic out in DBPro.

Thanks.

www.total-classics.com
D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 19th May 2006 01:38
You have to calculate the rotation incrementally within a loop. Each pass would effectively render the object in a new angle until it reached a given target angle. Same thing would be done for any kind of movement. The speed would be determined by the frame rate and the increment value used.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th May 2006 01:46
A very simple example:



That will give you 0.1 degree increments in 350 steps.



fuzz one
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 19th May 2006 01:57
thanks ogre, you've been helping me all day

ur the best, i understand the concept, but i was thinking of like exiting the current do loop, calling a gosub, and then doing the stuff in the gosub that has a loop, and then going back to the do loop.

working within one do loop just seems like i'm doing everything one incremental cycle at a time.

thanks again.

www.total-classics.com
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 19th May 2006 02:59
BatVink,

I don't think that you fully understood the problem.

picture using your code snippet in a main gameloop like this




Your for-loop would hang up the other parts of the main loop from functioning. Since you have a sync command in the for-loop, the rotation would be see; but anything else that needs to be done in the main loop would have to wait. Add to the fact that if the main loop is timer based; it could really mess things up.

Normally what I do is have an if condition based on a logic flag, and rather than a for-loop, I increment angle a certain amount each time through the main loop. when the target is reached then you have a control prevent that part of the coad from running, until the control flage is reset.
fuzz one
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 19th May 2006 03:51
thanks batvink and zenassem. I've applied the incremental if inside the do loop to my current(and first dbpro) project.

www.total-classics.com
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 19th May 2006 04:23
Yeah, but it's in a for/next loop, which can be used in exactly the same way as a do/loop.

Also, check out the curveangle command.

fuzz one
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 19th May 2006 04:31
hmm, curveangle seems cool, thanks for pointing me in a cool direction. i would say right, but im leaving the window open for more possibilities

www.total-classics.com
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 19th May 2006 05:29
Zotoaster,

My point was not whether it's in a for/next loop or a do/loop. My point was that if there is a for/next loop inside the main game loop, all the program flow will be limited to the for/next loop for the it's entire duration - before returning back to the main game loop.

So say for instance the for/next loop contained code to have an elevator move from the bottom to the top. The program would not process any other actions until the for/next loop is finished.

This is ok in certain situations. For example If I am making a 2d tile-based game. I can have a for/next loop draw the tiles to the screen every loop. Then I can handle input and the character animation.

But say in this game the character needs to jump and then land. I cannot simply place that code in a for/next loop. The reason: If I did, no other actions would be able to take place until the jumping code is finished.

Lastly, I am a strong believer in having one sync at the end of a game loop. Adding extra syncs in nested-loops inside the main game-loop can cause chaotic effects; especially if the game loop is timerbased.

I'm not sure if I am properly explaining myself. Basically, you don't want to interrupt the normal flow through the main game loop. The main loop should cycle and the code inside should increment a given value once each time through the game loop.
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 19th May 2006 14:58
Following on from what zenassem is saying, to provide a solution, you need to set up a function to handle the rotation.

The code might end up looking somewhat like this:


That way, the sync in the main loop actually updates the screen, but the function is what handles the rotate.

Hope that thought helps!
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 19th May 2006 16:23
@Dream and Death,

Yup, that's exactly what I was trying to get across.

The only part that is missing is an if statement or a control flag that controls whether the Object needs to be rotated to begin with. But I'm sure fuzz one can add that into the code you provided.

More often than not a code snippet can be more clear than a thousand words. I'll try to remember that.

Login to post a reply

Server time is: 2024-11-26 19:14:56
Your offset time is: 2024-11-26 19:14:56