Hi,
I am facing a with getting the mouse co-ordinates from the scene.
I will explain the scenario first. I am developing an application
which involves drawing a 2D floor plan and then developing the 3D
model. The creation of the 3D model is done using extrusion.
While the application is almost complete. I am facing a problem/bug in
creation of 2D floor plan. To the best of my knowledge the bug is
caused to error I am making in mapping the mouse co-ordinates on the
screen to 3D space. I read the many discussions in the forum but my
knowledge of 3D math is limited and I cannot fully follow. The 2D
floor plan is drawn on X -Y plane. HoverCamera is used. Pan angle is
180 and tilt is zero. The camera positions are
_camera.x = -100;
_camera.y = 100;
_camera.z = 0;
There is a an offset between the position I am pressing and where the
lines are appearing. Please do try out the code to see the offset.
My deadline is very near. So please help.
I am pasting the code below:
********************************************************************************************
package
{
import away3d.cameras.*;
import away3d.containers.*;
import flash.display.*;
import flash.events.*;
public class ExtrusionBaseClass extends Sprite
{
protected var _view : View3D;
protected var _camera : HoverCamera3D;
public function ExtrusionBaseClass()
{
_createView();
_createScene();
}
protected function _createView() : void
{
_camera = new HoverCamera3D();
_camera.tiltAngle = 0;
_camera.panAngle = 180;
_view = new View3D();
_view.x = 400;
_view.y = 300;
_view.camera = _camera;
addChild(_view);
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
protected function _createScene() : void
{
}
protected function _onEnterFrame(ev : Event) : void
{
_camera.hover();
_view.render();
}
}
}
*********************************************************************************
package {
import away3d.cameras.*;
import away3d.containers.*;
import away3d.core.base.*;
import away3d.core.geom.*;
import away3d.core.math.*;
import away3d.extrusions.*;
import away3d.materials.*;
import away3d.primitives.*;
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import wumedia.vector.*;
public class ExtrusionKitchenProject1 extends ExtrusionBaseClass
{
private var VerdanaSwf : Class;
private var _xpos:Array = new Array();
private var _ypos:Array = new Array();
private var sides:Number = 1;
private var init:Boolean = true;
private var firstTime:Boolean = true;
private var mesh:Mesh = new Mesh();
private var i:uint=0;
var segment0:Segment = new Segment();
var material:Material = new ColorMaterial(0xfff000);
var material1:WireColorMaterial = new
WireColorMaterial(0x123ff0);
var segment1:Segment = new Segment();
public function ExtrusionKitchenProject1()
{
super();
}
override protected function _createScene() : void
{
mesh.bothsides = true;
var material : WireColorMaterial = new
WireColorMaterial(0xFF0000);
material.wireColor = 0x000000;
material.thickness = 2;
mesh.material = material;
_view.scene.addChild(mesh);
_camera.x = -100;
_camera.y = 100;
_camera.z = 0;
segment0.moveTo(-400,100,0);
segment0.lineTo(200, 100,0);
segment0.moveTo(-100,300,0);
segment0.lineTo(-100,-100,0);
mesh.addSegment(segment0);
stage.addEventListener(MouseEvent.MOUSE_DOWN,
onMouseDown);
}
public function onMouseDown(event:MouseEvent):void {
if(firstTime)
{
_xpos[i] = _view.mouseX;
_ypos[i] = _view.mouseY;
firstTime = false;
i++;
}
else
{
_xpos[i] = _view.mouseX;
_ypos[i] = _view.mouseY;
segment1.moveTo(_xpos[i-1],- _ypos[i-1],0);
segment1.lineTo(_xpos[i],-_ypos[i],0);
mesh.addSegment(segment1);
i++;
}
}
}
}