Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/19/24 18:45
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, kzhao, 7th_zorro), 714 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
simple rotation per hour of gameplay... #391361
01/11/12 12:50
01/11/12 12:50
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
So... I was trying to get an entity to do a very slow rotation (one full rotation per hour of gameplay).

My first attempt was a little "stuttery". The leaps in rotations are very small, but still noticeable.
Code:
while(1)
{
 Planet.pan+=0.1;
 wait(-1)
}



My second attempt sort of worked, with a couple drawbacks:
-I had to limit the framerate (or else values would be too small to count for an angle)
-Sometimes got some random crashes
Code:
fps_max=30;

while(1)
{
 Planet.pan+=0.1*time_step/16;
 wait(1);
}



After several failed attempts based around the second method, I reverted to trying a modified version of the first one...
Code:
while(1)
{
 Planet.pan+=0.001;
 wait(-0.01)
}


This last method gives smoother rotations than the first, but for some reason it feels like a "sloppy" workaround to me. I have the feeling it would be better with some formula utilizing time_step (like in my second attampt).


My questions for you experts out there are...

-Why would I get random crashes? Could it be related to some wierd (framerate-spikes related) values messing up the division? Could it be related to large pan values? Is a "planet.pan%=360;" instruction recommended here?

-Are all three methods actually exactly "1rph" (one full rotation per hour of gameplay)?

-Even if it is 1rph (or not)... Is there a better way of achieving it?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: simple rotation per hour of gameplay... [Re: Carlos3DGS] #391362
01/11/12 12:58
01/11/12 12:58
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Code:
void rotateperhour(ENTITY* ent)
{
float seconds;
while(1)
{
seconds += time_frame;
ent.pan = seconds / 10;
wait(1);
}
}


Like this, probably not a nice way-

Re: simple rotation per hour of gameplay... [Re: Rei_Ayanami] #391364
01/11/12 13:23
01/11/12 13:23
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Very interesting, I had not thought of that aproach.
I do have a couple quetsions about it though.

since seconds is a float... it will eventually grow too large to fit in the variable during an extremely long gameplay session? Should I limit it with something like this?
seconds%=3600;
Would that be the correct math for a full rotation per hour?


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: simple rotation per hour of gameplay... [Re: Carlos3DGS] #391365
01/11/12 13:31
01/11/12 13:31
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
yeah, I guess that would be needed [as said, quick example^^]

Re: simple rotation per hour of gameplay... [Re: Rei_Ayanami] #391367
01/11/12 13:38
01/11/12 13:38
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Oops... my extra line messed it up!

I get the folowing error:
Quote:
Syntax error:Can't convert MOD:FLOAT:FLOAT:FLOAT.
<seconds%=3600;>


Complete code:
Code:
float seconds;
	
while(1)
{
	seconds+=time_frame;
	seconds%=3600;
	Planet.pan=seconds/10;
	wait(1);
}



Any ideas on what's wrong? This float dosn't like to be divided or what? lol

EDIT:
Changed seconds to var... That seems to have fixed the error, but the rotation is definately not 1rph...
(I'm not sure if the math is wrong or if it is caused by me changing the float to a var?)

Last edited by Carlos3DGS; 01/11/12 13:47.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: simple rotation per hour of gameplay... [Re: Rei_Ayanami] #391368
01/11/12 13:43
01/11/12 13:43
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Code:
const fixed  TICKS_PER_HOUR = 16 * 60 * 60;

while (1)
{
  my->pan = (total_ticks % TICKS_PER_HOUR) * 360 / TICKS_PER_HOUR;
  wait(1);
}



Just another suggestion.


Always learn from history, to be sure you make the same mistakes again...
Re: simple rotation per hour of gameplay... [Re: Uhrwerk] #391370
01/11/12 13:47
01/11/12 13:47
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
The problem is your seconds%=

Just do that:
if(seconds > 3600)
seconds-=3600;

Re: simple rotation per hour of gameplay... [Re: Uhrwerk] #391371
01/11/12 13:54
01/11/12 13:54
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
Thanks alot both of you!

And I managed to learn about 2 engine variables I had never used before (until now I only used time_step for these type of things).

How total_ticks keeps up though puzzles me. Since it counts all ticks, how does it manage to not grow too large to fit in whatever variable it is stored? (In the manuall it dosn't detail about that wierd behaviour and how it does it).


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: simple rotation per hour of gameplay... [Re: Rei_Ayanami] #391378
01/11/12 14:45
01/11/12 14:45
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline OP
User
Carlos3DGS  Offline OP
User

Joined: Oct 2008
Posts: 513
@Rei
changed seconds%=3600 to what you suggested but rotations are still way faster than 1rph. I timed it and it seems it is around 1 rotaton every 225 seconds (or 3.75 mins).

@Uhrwerk
your method looks awesome and the rotation does seem to be 1rph at a first glance (though i'm not going to time it for 1 hour right now).
The only problem will be when saving/loading my game. Your method will complicate things alot when I want to load a game at the same rotation it was saved. Since it starts counting at engine startup I would need an extra var to store the currrent ticks when the game is loaded, and subtract that from the formula. I will also need another var to store start rotation and add that to the pan somwhere in the formula. Thus complicating the calculations needed to be done each frame for all of my planets.



I would like to get Rei's version working properly. Also because it seems easier to understand at a first glance , but mainly because saving/loading seems much easier with that system. Each time a game is loaded all I would have to is reset seconds at the first frame after a load and then add the loaded pan.

I am still considering what complications each aproach could potencially have (Uhrwerk's system seems to require less calculations for calculating relative positions of orbiting moons for example).

All in all I would like to get both systems working to be able to decide which I will implement, but at the moment Rei's version does not seem to work as intended


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: simple rotation per hour of gameplay... [Re: Carlos3DGS] #391379
01/11/12 14:54
01/11/12 14:54
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Code:
void rotateperhour(ENTITY* ent)
{
   float ticks;
   while(1)
   {
      ticks = cycle(ticks+time_frame, 0, 57600);
      ent.pan = (ticks / 16) / 10;   //or  ent.pan = ticks / 160;
      wait(1);
   }
}

Remember guys ... time_step is in TICKS, and there are 16 TICKS in a SECOND.



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1