spring: Make clip behavior configurable
When the spring goes outside the envelope, we have a few options for bringing it back: either just let it overshoot, bounce off the limit or just clamp it. Instead of controlling that with #ifdef, let's make it a part of the spring state.
This commit is contained in:
parent
c24744ec91
commit
7eec9b32f7
@ -41,6 +41,7 @@ weston_spring_init(struct weston_spring *spring,
|
|||||||
spring->current = current;
|
spring->current = current;
|
||||||
spring->previous = current;
|
spring->previous = current;
|
||||||
spring->target = target;
|
spring->target = target;
|
||||||
|
spring->clip = WESTON_SPRING_OVERSHOOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
@ -71,22 +72,31 @@ weston_spring_update(struct weston_spring *spring, uint32_t msec)
|
|||||||
force * step * step;
|
force * step * step;
|
||||||
spring->previous = current;
|
spring->previous = current;
|
||||||
|
|
||||||
#if 0
|
switch (spring->clip) {
|
||||||
if (spring->current >= 1.0) {
|
case WESTON_SPRING_OVERSHOOT:
|
||||||
#ifdef TWEENER_BOUNCE
|
break;
|
||||||
spring->current = 2.0 - spring->current;
|
|
||||||
spring->previous = 2.0 - spring->previous;
|
case WESTON_SPRING_CLAMP:
|
||||||
#else
|
if (spring->current >= 1.0) {
|
||||||
spring->current = 1.0;
|
spring->current = 1.0;
|
||||||
spring->previous = 1.0;
|
spring->previous = 1.0;
|
||||||
#endif
|
} else if (spring->current <= 0.0) {
|
||||||
|
spring->current = 0.0;
|
||||||
|
spring->previous = 0.0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WESTON_SPRING_BOUNCE:
|
||||||
|
if (spring->current >= 1.0) {
|
||||||
|
spring->current = 2.0 - spring->current;
|
||||||
|
spring->previous = 2.0 - spring->previous;
|
||||||
|
} else if (spring->current <= 0.0) {
|
||||||
|
spring->current = -spring->current;
|
||||||
|
spring->previous = -spring->previous;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spring->current <= 0.0) {
|
|
||||||
spring->current = 0.0;
|
|
||||||
spring->previous = 0.0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
spring->timestamp += 4;
|
spring->timestamp += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,12 @@ struct weston_animation {
|
|||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
WESTON_SPRING_OVERSHOOT,
|
||||||
|
WESTON_SPRING_CLAMP,
|
||||||
|
WESTON_SPRING_BOUNCE
|
||||||
|
};
|
||||||
|
|
||||||
struct weston_spring {
|
struct weston_spring {
|
||||||
double k;
|
double k;
|
||||||
double friction;
|
double friction;
|
||||||
@ -120,6 +126,7 @@ struct weston_spring {
|
|||||||
double target;
|
double target;
|
||||||
double previous;
|
double previous;
|
||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
|
uint32_t clip;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
Loading…
Reference in New Issue
Block a user