Hi all,
I'm devoloping a planetarium and space simulator in as3. It has its own
3d math library, but for planet rendering I'm using away3d.
I've uploaded some screenshots here:
http://www.betaeridani.com/gallery/
Some images show planets in a double star system so they have an
unusual look :-)
And now my problem:
The screenshot
http://www.betaeridani.com/gallery/_specular_bad_reflection.jpg
shows the problem I'm having with specular reflections. The reflection
of the sun appears displaced to the left where it should be.
I've written a simple small Test class that replicates the problem above:
There is a blue sphere that represents the Earth and a yellow one that
represents the Sun.
There's also a light source located at the same coordinates as the Sun.
The reflection is correct as long as the x, y coordinates of the Planet
and the camera are equal
(http://www.betaeridani.com/gallery/_specular1.jpg)
but when you move the Planet or the camera and coordinates are no
longer equal, I get a wrong reflection
(http://www.betaeridani.com/gallery/_specular2.jpg) .
Am I missing something here?
package com.jon.test {
import away3d.cameras.Camera3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.core.render.Renderer;
import away3d.lights.DirectionalLight3D;
import away3d.materials.ColorMaterial;
import away3d.materials.PhongColorMaterial;
import away3d.primitives.Sphere;
import flash.display.Sprite;
public class Test1 extends Sprite{
private var _scene:Scene3D;
private var _camera:Camera3D;
private var _view:View3D;
private var _planet:Sphere;
private var _star:Sphere;
private var _light:DirectionalLight3D;
private var _planetMaterial:PhongColorMaterial;
private var _starMaterial:ColorMaterial;
public function Test1() {
}
public function init():void {
init3d();
createScene();
setTestCoordinates();
}
private function init3d():void {
_scene = new Scene3D();
_camera = new Camera3D({zoom:30});
_view = new View3D({
scene:_scene,
camera:_camera,
renderer:Renderer.BASIC
});
addChild(_view);
}
private function createScene():void {
_planetMaterial = new PhongColorMaterial(0x0000ff);
_starMaterial = new ColorMaterial(0xffff00);
_planetMaterial.shininess = 20;
_planet = new Sphere({material:_planetMaterial, radius:6378,
segmentsW:30, segmentsH:30});
_star = new Sphere({material:_starMaterial, radius:697000,
segmentsW:20, segmentsH:20});
_light = new DirectionalLight3D({color:0xffffff, ambient:.3,
diffuse:2, specular:.8});
//add objets to scene
_scene.addChild(_planet);
_scene.addChild(_star);
_scene.addChild(_light);
}
private function setTestCoordinates():void {
//planet coordinates
_planet.x = 0;
_planet.y = 4000;
_planet.z = 0;
//star coordinates
setStarCoordinates(15267000, 4565000, 148192000);
//camera coordinates
_camera.x = 0;
_camera.y = 0;
_camera.z = -95000;
//render
_view.render();
}
private function setStarCoordinates(x:int, y:int, z:int):void {
//light
_light.x = x;
_light.y = y;
_light.z = z;
//star coordinates = light coordinates
_star.x = x;
_star.y = y;
_star.z = z;
}
}
}