Be a Supporter!

Augmented Reality

  • 226 Views
  • 3 Replies
New Topic
Fifra
Fifra
  • Member since: May. 5, 2009
  • Offline.
Forum Stats
Member
Level 13
Movie Buff
Augmented Reality 2013-07-01 06:26:27

Trying to do some augmented reality in flash with as3. One however the following code is giving me trouble.
Error 1120 Access of undefined property Keyboard
Error 1180 Call to a possibly undefined method addFrameScript.

ps" this is my first time working with flash. Also, I'm am using papervision 3D.

package  {
	import flash.events.Event
	import flash.events.KeyboardEvent; //for rotation

	import org.papervision3d.scenes.*;
	import org.papervision3d.cameras.*;
	import org.papervision3d.objects.*;
	import org.papervision3d.objects.special.*;
	import org.papervision3d.objects.primitives.*;
	import org.papervision3d.materials.*;
	import org.papervision3d.materials.special.*;
	import org.papervision3d.materials.shaders.*;
	import org.papervision3d.materials.utils.*;
	import org.papervision3d.lights.*;
	import org.papervision3d.render.*;
	import org.papervision3d.view.*;
	import org.papervision3d.events.*;
	import org.papervision3d.core.utils.*;
	import org.papervision3d.core.utils.virtualmouse.VirtualMouse;

	[SWF(width=640, height=480, backgroundColor=0x808080, frameRate=30)]
	
	public class Cube4 extends PV3DARApp {
				
		private var _plane:Plane;
		private var _cube:Cube;
		
		public function SimpleCube() {
			// Initalize application with the path of camera calibration file and patter definition file.
			addEventListener(Event.INIT, _onInit);
			init('Data/camera_para.dat', 'Data/FifraMarker.pat');
	}
		
		private function _onInit(e:Event):void {
			
			var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2); // with wireframe.
			_plane = new Plane(wmat, 80, 80); // 80mm x 80mmãEU'
			_plane.rotationX = 180;
			_markerNode.addChild(_plane); // attach to _markerNode to follow the marker. / _markerNode ã« addChild

		
		var viewport:Viewport3D = new Viewport3D(0, 0, true, true);
		addChild(viewport);
		viewport.buttonMode = true;
                        
		var renderer:BasicRenderEngine = new BasicRenderEngine();
                        
		var scene:Scene3D = new Scene3D();
                        
		var camera:Camera3D = new Camera3D();
		camera.zoom = 11;
		camera.focus = 100;                 

		var mam:MovieMaterial = new MovieMaterial(sq1);
		mam.interactive = true;
		mam.smooth = true;
		mam.animated = true;

		var mam2:MovieMaterial = new MovieMaterial(sq2);
		mam2.interactive = true;
		mam2.smooth = true;
		mam2.animated = true;

		var mam3:MovieMaterial = new MovieMaterial(sq3);
		mam3.interactive = true;
		mam3.smooth = true;
		mam3.animated = true;

		var mam4:MovieMaterial = new MovieMaterial(sq4);
		mam4.interactive = true;
		mam4.smooth = true;
		mam4.animated = true;

		var mam5:MovieMaterial = new MovieMaterial(sq5);
		mam5.interactive = true;
		mam5.smooth = true;
		mam5.animated = true;

		var mam6:MovieMaterial = new MovieMaterial(sq6);
		mam6.interactive = true;
		mam6.smooth = true;
		mam6.animated = true;

		var cube:Cube = new Cube(new MaterialsList({front:mam, back:mam2, left:mam3, right:mam4,top:mam5, bottom:mam6}), 200, 200, 200, 10, 10, 10); //building the cube
		scene.addChild(cube);

		
		
			_markerNode.addChild(cube);
			cube.localRotationX = 30;
			
			stage.addEventListener(Event.ENTER_FRAME, _rotate);

function _rotate(e:Event):void
{
	stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
	
function myKeyDown(e:KeyboardEvent):void {
switch (e.keyCode) {
case Keyboard.LEFT :
cube.rotationY += 0.015;
break;

case Keyboard.RIGHT :
cube.rotationY -= 0.015;
break;

case Keyboard.UP :
cube.rotationX += 0.015;
break;

case Keyboard.DOWN :
cube.rotationX -= 0.015;
break;
}
		}
			renderer.renderScene(scene, camera, viewport);
		}
		
		}
	}
	
}

Augmented Reality

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Augmented Reality 2013-07-01 09:36:10

At 7/1/13 06:26 AM, Fifra wrote: package {
import flash.events.Event
import flash.events.KeyboardEvent; //for rotation

import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.utils.virtualmouse.VirtualMouse;

You do not need all those classes.
While importing unused classes does not produce overhead, it reduces the readability a lot.
For instance, you are missing one class that you are actually using.

stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);

no need to add this every frame.

Error 1180 Call to a possibly undefined method addFrameScript.

this method is not used in the code that you posted.

If you post errors, post the line on which they occur.

Fifra
Fifra
  • Member since: May. 5, 2009
  • Offline.
Forum Stats
Member
Level 13
Movie Buff
Response to Augmented Reality 2013-07-01 11:13:37

Yes thank you i was missing a particular import. I am new to as3. now the program does not give me errors however all i get is a grey screen.... hmmm. I'll see what i can do about with that

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Augmented Reality 2013-07-01 13:39:11

Please keep Flash related threads, including ones about ActionScript, in the Flash forum.