java - How to change coordinate regularly using gl.glTranslatef() ? -
having following display()
-
float tranx , trany , tranz ; public void display(glautodrawable gldrawable) { final gl gl = gldrawable.getgl(); gl.glloadidentity(); gl.glpushmatrix(); gl.gltranslatef(tranx ,trany ,tranz); gl.glcalllist(i); gl.glpopmatrix(); tranx += 0.05; trany += 0.05; tranz += 0.05; }
as can see each display()
calling matrix of object in gl.glcalllist(i)
saved , coordinates change gl.gltranslatef(tranx ,trany ,tranz)
.
suppose @ stage want save object @ current position (after gl.gltranslatef
calling ) , start translate tranx
, trany
, tranz
values .
how save object position considering above gl.glpushmatrix()
, gl.glpopmatrix()
?
push/pop matrices there accumulate complex matrix transformations otherwise painful hand. storing , moving object positions, keeping variables have done correct. expand on and, start moving in another, add directionx/y/z. eg, tranx += directionx etc. when want change direction, set directionx/y/z different value.
the speed change depending on how fast computer though. you'll want find time since last frame (or last call display) , this: transx += velocityx * deltatime etc.
if want move object 1 point specific point, want key-framed interpolation. example position = pointa * (1.0 - x) + pointb * x , make x move 0 1 (x += speed * deltatime). when x above one, pointa becomes pointb , pointb set next position in list. subtract 1.0 x , continue.
Comments
Post a Comment