00001
00002
00003
00004 package org.hfbk.vis;
00005
00006 import org.lwjgl.util.vector.Vector3f;
00007
00019 public class TransitionViewpoint extends Viewpoint {
00020 Viewpoint fromView, toView;
00021
00022 float speed=1f, transition=0;
00023
00024
00032 public TransitionViewpoint(Viewpoint viewpoint, Viewpoint viewpoint2, float speed) {
00033 this.fromView=viewpoint;
00034 this.toView=viewpoint2;
00035 this.speed=speed;
00036 }
00037
00043 public boolean checkArrived(){
00044 return transition>=1;
00045 }
00046
00047
00048 float ipol(float a, float b, float t){
00049 return a*(1-t)+b*t;
00050 }
00051
00052
00053 float aipol(float a, float b, float t){
00054 float pi=(float)Math.PI;
00055 if (Math.abs(a-b)>Math.PI){
00056 a=(a+pi)%(2*pi);
00057 b=(b+pi)%(2*pi);
00058 return (a*(1-t)+b*t + pi)%(2*pi);
00059 }else
00060 return a*(1-t)+b*t;
00061 }
00062
00063
00064 void render(float dt) {
00065 transition+=dt*speed;
00066 float ftrans=(float)Math.sin((transition-.5f)*Math.PI)/2+.5f;
00067
00068 angle= aipol( fromView.angle, toView.angle,ftrans);
00069 elevation=aipol( fromView.elevation, toView.elevation,ftrans);
00070 Vector3f.add(
00071 (Vector3f)new Vector3f(fromView).scale(1-ftrans),
00072 (Vector3f)new Vector3f(toView).scale(ftrans),
00073 this
00074 );
00075
00076 super.render(dt);
00077 }
00078 }