FLARCodeImage:Utility for FLARToolKit

Source of PV3DPanel

PV3DPanel is zoomable and rotatable child of BasicView.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* 
 * PROJECT: FLARToolKit
 * --------------------------------------------------------------------------------
 * This work is based on the NyARToolKit developed by
 *   R.Iizuka (nyatla)
 * http://nyatla.jp/nyatoolkit/
 *
 * The FLARToolKit is ActionScript 3.0 version ARToolkit class library.
 * Copyright (C)2008 Saqoosha
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this framework; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * For further information please contact.
 *    http://www.libspark.org/wiki/saqoosha/FLARToolKit
 *    <saq(at)saqoosha.net>
 * 
 * For further information of this Class please contact.
 *    http://www.libspark.org/wiki/saqoosha/FLARToolKit
 *    <taro(at)tarotaro.org>
 *
 */
package org.tarotaro.flash.pv3d
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.view.BasicView;
 
    /**
     * ...
     * @author tarotarorg
     */
    public class PV3DPanel extends BasicView
    {
        private var _model:DisplayObject3D;
        private var _dragStart:Point;
 
        public function PV3DPanel(width:int = 640,height:int = 480,model:DisplayObject3D = null) 
        {
            super(width, height, true);
            var bd:BitmapData = new BitmapData(width, height, true, 0xFFFFFF);
            var bmp:Bitmap = new Bitmap(bd);
            this.addChild(bmp);
            this.model = model;
            this.addEventListener(MouseEvent.MOUSE_DOWN, startRotate,false,0,true);
            this.addEventListener(MouseEvent.MOUSE_UP, endRotate, false, 0, true);
            this.addEventListener(MouseEvent.MOUSE_WHEEL, doZoom,false,0,true);
            this.startRendering();
        }
 
        private function doZoom(e:MouseEvent):void 
        {
            var newZoom:Number = e.delta + this.camera.zoom;
            if (newZoom > 0) {
                this.camera.zoom = newZoom;
            }
        }
 
        private function endRotate(event:MouseEvent):void 
        {
            try {
                this.removeEventListener(MouseEvent.MOUSE_MOVE , rotateModel);
            } catch (e:Error) {}
        }
 
        private function startRotate(event:MouseEvent):void 
        {
            this._dragStart = new Point(event.stageX , event.stageY);
            try {
                this.removeEventListener(MouseEvent.MOUSE_MOVE , rotateModel);
            } catch (e:Error) {}
            this.addEventListener(MouseEvent.MOUSE_MOVE , rotateModel);
        }
 
        private function rotateModel(event:MouseEvent):void {
            if (this.model) {
                this.model.rotationY -= (event.stageX - this._dragStart.x) ;
                this.model.rotationX += (event.stageY - this._dragStart.y) ;
                this._dragStart.x = event.stageX;
                this._dragStart.y = event.stageY;
            }
        }
 
        public function get model():DisplayObject3D { return _model; }
 
        public function set model(value:DisplayObject3D):void 
        {
            try {
                this.scene.removeChild(this._model);
            }catch (e:Error) { trace(e); }
            this._model = value;
            if (this._model) this.scene.addChild(this._model);
        }
 
    }
 
}
Ads

Ad

Ad

Share

  • Add this article to hatena bookmark
  • 0

Follow

Ads

Ad

Comments

  1. oruchreis says:

    Hi,
    I’m trying to calculate 3D position of a mouse click position by detected marker’s plane. Is there any easy way to find 3D postion on the marker’s plane? I’ve tried to intersect 2D position with marker’s plane. I can get the ray vector fo the mouse click position by flarCamera3D’s unproject method. I also can get the marker’s 3D position. But I need to find the normal vector of the marker’s plane. So I can build a plane3D with setNormalAndPoint method. Then I can intersect the ray with this plane and the result will be the 3D position of the 2D mouse position. My codes are here:
    var ray:Number3D = flarCamera3D.unproject(mouse.x,mouse.y);
    var p:Plane3D = new Plane3D();
    var normal: Number3D = I DONT KNOW HOW TO FIND??
    p.setNormalAndPoint(normal, markerPosition);
    var intersect:Number3D = p.getIntersectionLineNumbers(flarCamera3D.position, ray);

    I will appreciated if you can help, I didn’t any solutions for days.

  2. tarotarorg says:

    Hi, oruchreis.

    Sorry. I could not find a solution for you.

    Thank you.

Leave a Comment

Your email address will not be published. Required fields are marked *