Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (NewbieZorro, TipmyPip, 1 invisible), 19,045 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Animation Frame based on distance #187261
03/06/08 09:46
03/06/08 09:46
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
hey everyone,

I wanted to know if anyone would know how to go about doing this in c-script. Say I have an animation, maybe of a model opening its mouth made in 10 frames. I have a distance value between 2 points. If the distance value is say at max 300, I need a formula that will put the animation of the model at the 10th frame, based on the distance value. So:

If the distance value is at 0, the animation is at frame 0.
If the distance value is at the 300 max, the animation is at frame 10.

What formula could I use so that any distance between 0 and 300 would correlate to a frame of animation? Can the formula accomodate different total frames of animation and different max distances?

Last edited by jumpman; 03/06/08 10:37.
Re: Animation Frame based on distance [Re: jumpman] #187262
03/06/08 12:23
03/06/08 12:23
Joined: Dec 2005
Posts: 490
Germany/Berlin-Velten
kasimir Offline
Senior Member
kasimir  Offline
Senior Member

Joined: Dec 2005
Posts: 490
Germany/Berlin-Velten
something like this:

my.frame = distance / max_distance * 10; //max_distance = 300



Re: Animation Frame based on distance [Re: jumpman] #187263
03/06/08 12:52
03/06/08 12:52
Joined: Feb 2008
Posts: 9
Germany, Cologne
dinosaur Offline
Newbie
dinosaur  Offline
Newbie

Joined: Feb 2008
Posts: 9
Germany, Cologne
should be like this:

frameNo = (int)((float)actDist / ( (float)maxDist / (float)( frameCount - 1 ) ))+1

Re: Animation Frame based on distance [Re: dinosaur] #187264
03/06/08 18:20
03/06/08 18:20
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
@Dinosaur

c-script takes care of type casting for you, so you don't have to worry about all the mess. Also, ".frame" accepts fractions as well (for interpolating), so converting to integer isn't necesary...


xXxGuitar511
- Programmer
Re: Animation Frame based on distance [Re: xXxGuitar511] #187265
03/07/08 10:31
03/07/08 10:31
Joined: Feb 2008
Posts: 9
Germany, Cologne
dinosaur Offline
Newbie
dinosaur  Offline
Newbie

Joined: Feb 2008
Posts: 9
Germany, Cologne
@xXxDisciple

Yes I know that c-Script and LiteC care of type casting, but I want to control exactly what happens.

For example: If the used variables (maxDist etc.) are declared as int than there will be to many rounding errors.
It might not be a problem in the case of this animation-cycle but it could be in other circumstances. So I always use casts to be sure what happens.

regards
Dinosaur

Re: Animation Frame based on distance [Re: dinosaur] #187266
03/07/08 18:12
03/07/08 18:12
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
...Understandable, and indeed a good habit


xXxGuitar511
- Programmer
Re: Animation Frame based on distance [Re: xXxGuitar511] #187267
03/07/08 18:37
03/07/08 18:37
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
thanks for the input guys, though I am a little lost as to what the difference between these two are:


This one uses more hard scripted values am I correct?:

my.frame = distance / max_distance * 10; //max_distance = 300.

Does this one seem more flexible, because the values can be defined beforehand such as max distance?:

frameNo = (int)((float)actDist / ( (float)maxDist / (float)( frameCount - 1 ) ))+1

Why is there (float)?, sorry Ive never used float in C_Script yet.

Re: Animation Frame based on distance [Re: jumpman] #187268
03/08/08 07:40
03/08/08 07:40
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
type casting won't work in c-script. Only in Lite-C...

...Use the first one


xXxGuitar511
- Programmer

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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