My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
113
114
115
116
117
118
119
120
121
122
package
{
import flash.events.Event;
import flash.events.MouseEvent;

import jiglib.physics.RigidBody;
import jiglib.plugin.papervision3d.Papervision3DPhysics;
import jiglib.plugin.papervision3d.constraint.MouseConstraint;

import org.papervision3d.cameras.CameraType;
import org.papervision3d.core.math.Number3D;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.layer.ViewportLayer;
import org.papervision3d.view.layer.util.ViewportLayerSortMode;

/**
* Dragging objects in 3D using MouseConstrait
* @author Reynaldo a.k.a. reyco1
*
*/
[SWF(width="900", height="700", backgroundColor="#000000", frameRate="60")]
public class MouseConstraintTest extends BasicView
{
private var physics:Papervision3DPhysics;
private var sceneLight:PointLight3D;
private var mouseConstraint:MouseConstraint;
private var vplObjects:ViewportLayer;

public function MouseConstraintTest()
{

super(stage.stageWidth, stage.stageHeight, true, true, CameraType.TARGET);

physics = new Papervision3DPhysics(scene, 8);

setupVPLayer();
setupLighting();
createFloor();
setCamera();
createBoxes();
startRendering();
}

private function setupVPLayer():void
{
vplObjects = new ViewportLayer(viewport, null);
vplObjects.layerIndex = 2;
vplObjects.sortMode = ViewportLayerSortMode.Z_SORT;
viewport.containerSprite.addLayer(vplObjects);
}

private function setupLighting():void
{
sceneLight = new PointLight3D(true, true);
sceneLight.x = 0;
sceneLight.y = 400;
sceneLight.z = -300;
}

private function createFloor():void
{
physics.createGround(new WireframeMaterial(0xFFFFFF, 0), 1800, 0);

var floor:Plane = new Plane(new WireframeMaterial(0xFFFFFF), 10000, 10000, 10000*0.001, 10000*0.001);
floor.rotationX = 90;
floor.y = -200
scene.addChild(floor);
}

private function setCamera():void
{
camera.y = 500
camera.focus = 100;
camera.zoom = 5;
}

private function createBoxes():void
{
var randomBox:RigidBody;
var material:MaterialsList = new MaterialsList();
var flatShadedMaterial:FlatShadeMaterial = new FlatShadeMaterial(sceneLight, 0x77ee77);
flatShadedMaterial.interactive = true;
material.addMaterial(flatShadedMaterial, "all");

for(var a:Number = 0; a<10; a++)
{
randomBox = physics.createCube(material, 100, 100, 100);
randomBox.y = a * 100 + 75;
randomBox.x = ((a * 150) + 150) - 750;
randomBox.mass = 2;
physics.getMesh(randomBox).addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleMousePress);
vplObjects.addDisplayObject3D(physics.getMesh(randomBox));
}
}

private function handleMousePress(event:InteractiveScene3DEvent):void
{
mouseConstraint = new MouseConstraint(event.displayObject3D, new Number3D(0, 0, 1), camera, viewport);
stage.addEventListener(MouseEvent.MOUSE_UP, removeMouseConstraint);
}

private function removeMouseConstraint(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, removeMouseConstraint);
mouseConstraint.destroy();
mouseConstraint = null;
}

override protected function onRenderTick(event:Event = null):void
{
physics.step();
renderer.renderScene(scene, camera, viewport);
}

}
}

Change log

r220 by muzerly on Oct 31, 2011   Diff
Created or replaced branch /trunk from
/trunk:218
Go to: 
Project members, sign in to write a code review

Older revisions

r218 by muzerly on Oct 31, 2011   Diff
test
r89 by muzerly on Apr 22, 2009   Diff
Added the maxDistance constraint and
HingeJoint that will be used to create
the Ragdoll. also added a test in
examples.
And don't need the "addConstraint"
...
r79 by reyco1 on Apr 10, 2009   Diff
Added new MouseConstraint.as to a
'constraint' folder for the
Papervision3D plugin. Also added an
example to the papervision3d folder
under examples.
All revisions of this file

File info

Size: 3802 bytes, 122 lines

File properties

svn:executable
*
Powered by Google Project Hosting