To look at the horizon

Software: Away3D 4.x

Nusakan, Newbie
Posted: 12 May 2015 03:22 PM   Total Posts: 10

I have a camera with a howerController to move her around a sphere.

What I would like to obtain is a zomm in the style of in Google Earth (that on having approached the object, the chamber turns towards the horizon instead of looking at the center of the sphere)

I have searched very much in Internet and there is nothing similar.

There is a way of doing this?

   

Nusakan, Newbie
Posted: 21 May 2015 02:03 PM   Total Posts: 10   [ # 1 ]

Hello again.

I have modified the example of “GlobeMaterialsTutorialListing03” to try to put the moon in the position of the camera (or rather, in front of her) then to replace it with a new camera that the hovercontroller does not use.

But I supposed what the moon would remain in the center of the view but it is not like that. It moves of erratic form and I do not know why

This one is the file modified “GlobeMaterialsTutorialListingBase”:

package
{
import away3d.containers.View3D;
import away3d.controllers.HoverController;
import away3d.materials.lightpickers.StaticLightPicker;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;

import away3d.materials.TextureMaterial;
import away3d.textures.BitmapTexture;
import away3d.entities.Mesh;
import away3d.containers.ObjectContainer3D;
import away3d.primitives.SphereGeometry;
import away3d.utils.Cast;

public class GlobeMaterialsTutorialListingBase extends Sprite
{
  // Protected.
  protected var _view:View3D;
  protected var _lightPicker:StaticLightPicker;
  protected var _cameraController:HoverController;

  // Camera control.
  private var _mouseIsDown:Boolean;
  private var _lastPanAngle:Number;
  private var _lastTiltAngle:Number;
  private var _lastMouseX:Number;
  private var _lastMouseY:Number;
  private var _tiltIncrement:Number = 0;
  private var _panIncrement:Number = 0;

  private const WIDTH:Number = 240;
  private const HEIGHT:Number = 320;
 
  // Diffuse map for the Moon’s surface.
  [Embed(source=”../embeds/moon.jpg”)]
  public static var MoonSurfaceDiffuse:Class;
 
  private var elevation:Number = 0;
  private var azimuth:Number = 0;
  var _panAngle:Number = 0;
  var _tiltAngle:Number = 0;
  var radius:Number = 100;
 
  private var _moon:ObjectContainer3D;

  public function GlobeMaterialsTutorialListingBase() {
  super();
  addEventListener( Event.ADDED_TO_STAGE, addedToStageHandler );
  }

  //——————————————————————————————————-
  // Private.
  //——————————————————————————————————-

  private function initialize():void {
  initStage();
  initAway3d();
  createMoon();
  onSetup();
  addEventListener( Event.ENTER_FRAME, enterframeHandler );
  }

  private function initStage():void {
  stage.scaleMode = StageScaleMode.NO_SCALE;
  stage.align = StageAlign.TOP_LEFT;
  stage.frameRate = 60;
  stage.addEventListener( MouseEvent.MOUSE_DOWN, stageMouseDownHandler );
  stage.addEventListener( MouseEvent.MOUSE_UP, stageMouseUpHandler );
  stage.addEventListener( MouseEvent.MOUSE_WHEEL, stageMouseWheelHandler );
  }
 
  private function createMoon():void {
  // Material.
  var moonMaterial:TextureMaterial = new TextureMaterial( Cast.bitmapTexture( MoonSurfaceDiffuse ) );
  moonMaterial.gloss = 5;
  moonMaterial.lightPicker = _lightPicker;
  // Container.
  _moon = new ObjectContainer3D();
  //_moon.rotationY = rand( 0, 360 );
  _view.scene.addChild( _moon );
  // Surface geometry.
  var moonSurface:Mesh = new Mesh( new SphereGeometry( 50, 200, 100 ), moonMaterial );
  //moonSurface.x = 1000;
  _moon.addChild( moonSurface );
  }

  protected function initAway3d():void {
  // View.
  _view = new View3D();
  _view.backgroundColor = 0x000000;
  _view.width = WIDTH;
  _view.height = HEIGHT;
  _view.antiAlias = 4;
  _view.camera.lens.far = 15000;
  _view.addSourceURL( “srcview/index.html” );
  _view.forceMouseMove = true;
  addChild( _view );
  // Camera.
  _cameraController = new HoverController( _view.camera, null, 0, 0, 300 );
  _cameraController.yFactor = 1;
  // Lights.
  _lightPicker = new StaticLightPicker( [] );
  }

  private function update():void {
  onUpdate();
  if( _mouseIsDown ) {
  _cameraController.panAngle = 0.4 * ( _view.mouseX - _lastMouseX ) + _lastPanAngle;
  _cameraController.tiltAngle = 0.4 * ( _view.mouseY - _lastMouseY ) + _lastTiltAngle;
 
  _tiltAngle = 0.4 * ( _view.mouseY - _lastMouseY ) + _lastTiltAngle;
  _panAngle = 0.4 * ( _view.mouseX - _lastMouseX ) + _lastPanAngle;
 
  elevation = _tiltAngle / 28.647889756541160438399077407053;
  azimuth = _panAngle / 57.295779513082320876798154814105;
  // Spherical to cartesian.
  _moon.x = radius * Math.cos( elevation ) * Math.sin( azimuth );
  _moon.y = radius * Math.sin( elevation );
  _moon.z = radius * Math.cos( elevation ) * Math.cos( azimuth );
 
 
  trace(“_cameraController.panAngle: ” + _cameraController.panAngle);
  trace(“_panAngle: ” + _panAngle);
  trace(“_cameraController.tiltAngle: ” + _cameraController.tiltAngle);
  trace(“_tiltAngle: ” + _tiltAngle);
  trace(” “);
 
  }
  //_cameraController.panAngle += _panIncrement;
  //_cameraController.tiltAngle += _tiltIncrement;
  _view.render();
  }

  //——————————————————————————————————-
  // Event handlers.
  //——————————————————————————————————-

  private function addedToStageHandler( event:Event ):void {
  removeEventListener( Event.ADDED_TO_STAGE, addedToStageHandler );
  initialize();
  }

  private function stageMouseDownHandler( event:MouseEvent ):void {
  _mouseIsDown = true;
  _lastPanAngle = _panAngle;
  _lastTiltAngle = _tiltAngle;
  _lastMouseX = stage.mouseX;
  _lastMouseY = stage.mouseY;
  }

  private function stageMouseWheelHandler( event:MouseEvent ):void {
  /*_cameraController.distance -= event.delta * 5;
  if( _cameraController.distance < 150 )
  _cameraController.distance = 150;
  else if( _cameraController.distance > 2000 )
  _cameraController.distance = 2000;*/
  }

  private function stageMouseUpHandler( event:MouseEvent ):void {
  _mouseIsDown = false;
  }

  private function enterframeHandler( event:Event ):void {
  update();
  }

  //——————————————————————————————————-
  //

   

Nusakan, Newbie
Posted: 21 May 2015 02:05 PM   Total Posts: 10   [ # 2 ]

Hello again.

I have modified the example of “GlobeMaterialsTutorialListing03” to try to put the moon in the position of the camera (or rather, in front of her) then to replace it with a new camera that the hovercontroller does not use.

But I supposed what the moon would remain in the center of the view but it is not like that. It moves of erratic form and I do not know why

This one is the file modified “GlobeMaterialsTutorialListingBase”:

private function update():void {
   onUpdate
();
   if( 
_mouseIsDown {
    _cameraController
.panAngle 0.4 * ( _view.mouseX _lastMouseX ) + _lastPanAngle;
    
_cameraController.tiltAngle 0.4 * ( _view.mouseY _lastMouseY ) + _lastTiltAngle;
    
    
_tiltAngle 0.4 * ( _view.mouseY _lastMouseY ) + _lastTiltAngle;
    
_panAngle 0.4 * ( _view.mouseX _lastMouseX ) + _lastPanAngle;
    
    
elevation _tiltAngle 28.647889756541160438399077407053;
    
azimuth _panAngle 57.295779513082320876798154814105;
    
// Spherical to cartesian.
    
_moon.radius Math.coselevation ) * Math.sinazimuth );
    
_moon.radius Math.sinelevation );
    
_moon.radius Math.coselevation ) * Math.cosazimuth );
    
    
    
trace("_cameraController.panAngle: " _cameraController.panAngle);
    
trace("_panAngle: " _panAngle);
    
trace("_cameraController.tiltAngle: " _cameraController.tiltAngle);
    
trace("_tiltAngle: " _tiltAngle);
    
trace(" ");
    
   
}
   
//_cameraController.panAngle += _panIncrement;
   //_cameraController.tiltAngle += _tiltIncrement;
   
_view.render();
  

And here you can see the result:
http://perso.wanadoo.es/o_o_c/GlobeMaterialsTutorialListing03.zip

Can someone give me a track of what is happening?

Thank you.

Forgive for my English

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X