Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

27. May 2012, 02:13:58 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)View, point, and transformations...
Pages: [1]
Print
Author Topic: View, point, and transformations...  (Read 636 times)
BrazilianBoy
Becoming dependent
**
Offline Offline

Posts: 208


l_p_camargo@hotmail.com
View Profile Email
« on: 26. November 2007, 02:47:57 pm »


Does anyone know how to rotate the view around a point in space  Huh (The point is my player's position, I want to achieve an "orbit" behavior).

Lucas.
Logged

Getting my hands dirty Smiley
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 26. November 2007, 03:06:46 pm »

This code should do the trick:

Code:
final View view = env.getView();
final AngleInterpolater angleInter = new AngleInterpolater( 1.0f );
angleInter.startIncreasing( getGameMicroTime() );
this.getUpdater().addUpdatable( new Updatable()
{
    final Point3f viewPos = new Point3f( view.getPosition() );
    final float dist = view.getPosition().distance( Point3f.ZERO );
   
    public void update( long gameTime, long frameTime, TimingMode timingMode )
    {
        final long gameMicros = timingMode.getMicroSeconds( gameTime );
       
        final float angle = angleInter.getValue( gameMicros );
       
        viewPos.setX( FastMath.sin( angle ) * dist );
        viewPos.setZ( FastMath.cos( angle ) * dist );
       
        view.lookAt( viewPos, Point3f.ZERO, Vector3f.POSITIVE_Y_AXIS );
    }
} );

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic