Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 911 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Mathematical Problem #432945
11/19/13 23:24
11/19/13 23:24
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
Hi,

I am creating some sort of interactive slideshow.
So here is what I want to do:
I want to increase a value, for example a distance, to a specific value, in a given fixed(!) time.
So far my function works fine. But I need too add a third component with wich I have a lot of problems. I want to smooth the movement in and out. I have no problem to do that with a not fixed timeframe, but I need a fixed one.
My problem is, that I don't now how much time is gone on a specific position, because I use time_step to be framerate independent.

what I have (works fine):
Code:
var camDistance; // filled in another function

void MoveToOrbit(var distance, var time)
{
  var t = 0;
  while(t < time)
  {
    t += 16 * time_step;
    var factor = t / time;  // actual position in timeframe
    
    var distDif = abs(camDistance - distance); //get distance
    var nDist = camDistance;
    if(distance < camDistance)
    {
      nDist -= distDif * factor; 
    }
    else
    {
      nDist += distDif * factor;
    }

    //(...) here the nDist var is put to use, for cameraDistance
    wait(1);
  }
  // (...) here the camDistance value and the actual camera value is set to distance-functionparameter to correct small discrepancies 
}



What I want:

void MoveToOrbit(var distance, var time, var smoothTime)

I hope someone can help me with that.

Greetings,
Patrick

Re: Mathematical Problem [Re: jenGs] #432947
11/20/13 01:39
11/20/13 01:39
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Code and usage just copy&paste to sed and run.
Also answers your question of knowing how much time has passed.
Code:
#include <acknex.h>
#include <default.c>
#define PRAGMA_POINTER

// t = time passed
// b = initial value
// c = change in value
// d = duration in which initial value becomes b+c

var easeInOutQuad(var t, var b,var c,var d) {
	if(t>=d)return b +c;
	t /= d/2;
	if (t < 1) return c/2*t*t + b;
	t--;
	return -c/2 * (t*(t-2) - 1) + b;
}

var easeInOutCubic(var t, var b,var c,var d) {
	if(t>=d)return b +c;
	t /= d/2;
	if (t < 1) return c/2*t*t*t + b;
	t -= 2;
	return c/2*(t*t*t + 2) + b;
}
	

void main(){
	level_load(NULL);
	ENTITY* cube = ent_create(CUBE_MDL,nullvector,NULL);
	camera->y -= 200;
	camera->pan = 90;
	
	
	var initial_value = -100;
	var delta_value = 200; // value will be 100 in the end (-100+200 = 100)
	var time_passed = 0;
	var duration = 2;
	
	while(!key_esc){
		if(key_space){
			cube->x = initial_value;
			time_passed = 0;
		}
		
		if(time_passed<duration)cube->x = easeInOutQuad(time_passed,initial_value,delta_value,duration);
		time_passed += time_step/16;//convert time_step to seconds

		wait(1);	
	}
}



Stolen from here: http://www.gizma.com/easing/#quad1


3333333333
Re: Mathematical Problem [Re: Quad] #432968
11/20/13 10:48
11/20/13 10:48
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
Thank you, that was very helpful.
With some small modification I am able to create a keyframe based movement system.

Greetings,
Patrick


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

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