Last active
September 27, 2019 20:31
-
-
Save ConfidantCommunications/3e8779f35963a09e41acd23e4d7a3dbc to your computer and use it in GitHub Desktop.
Heaps: Dragging object in 3D space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h3d.col.Point; | |
import h3d.shader.ColorAdd; | |
import h3d.scene.fwd.DirLight; | |
import hxd.Event; | |
import hxd.fmt.grd.Data; | |
class HeapsDrag extends hxd.App { | |
var rnd : hxd.Rand; | |
var light : h3d.scene.fwd.DirLight; | |
var obj : h3d.scene.Object; | |
var b : h2d.Interactive; | |
var shadow :h3d.pass.DefaultShadowMap; | |
function initInteraction( i : h3d.scene.Interactive, m : h3d.scene.Object ) { | |
var color = 0xccffcc; | |
var originalPos:Point; | |
var heldObject:h3d.scene.Object; | |
var originalCameraPos:h3d.Vector; | |
i.bestMatch = true; | |
i.onOver = function(e : hxd.Event) { | |
trace("over"); | |
}; | |
i.onMove = i.onCheck = function(e:hxd.Event) { | |
// trace("move:"+e.toString()); // EMove[-5,-22] or ECheck[-18,-41] | |
if(heldObject == m){ | |
m.x = originalPos.x + e.relX; | |
m.y = originalPos.y + e.relY; | |
// m.z = originalPos.z + e.relZ; | |
s3d.camera.pos = originalCameraPos; | |
} | |
}; | |
i.onPush = function (e:hxd.Event){ | |
// trace("modelx:"+m.x+" eventX:"+e.relX); | |
trace("modelx:"+m.x+" modely:"+m.y+" modelz:"+m.z); | |
//EPush[-5,-31],button=0 | |
heldObject = m; | |
originalCameraPos = s3d.camera.pos; | |
originalPos = new Point(m.x-e.relX ,m.y-e.relY ,m.z-e.relZ ); | |
}; | |
i.onRelease = function (e:hxd.Event){ | |
// trace("release:"+e.toString()); | |
heldObject = null; | |
originalCameraPos = null; | |
originalPos = null; | |
}; | |
} | |
override function init() { | |
light = new h3d.scene.fwd.DirLight(new h3d.Vector( 0.3, -0.4, -0.9), s3d); | |
light.enableSpecular = true; | |
light.color.set(0.28, 0.28, 0.28); | |
s3d.lightSystem.ambientLight.set(0.74, 0.74, 0.74); | |
s3d.lightSystem.ambientLight.setColor(0x909090); | |
new h3d.scene.fwd.DirLight(new h3d.Vector( 0.3, -0.4, -0.9), s3d); | |
var cache = new h3d.prim.ModelCache(); | |
obj = cache.loadModel(hxd.Res.C1C28FS_fbx); | |
// obj.scale(1);//or (1/5) | |
// obj.rotate(0,0,Math.PI / 2); | |
obj.x = 0; | |
obj.y = 0; | |
obj.z = 0; | |
s3d.addChild(obj); | |
var int = new h3d.scene.Interactive(obj.getCollider(),s3d); | |
initInteraction(int,obj); | |
s3d.camera.target.set(0, 0, 0); | |
s3d.camera.pos.set(20, 20, 280); | |
shadow = s3d.renderer.getPass(h3d.pass.DefaultShadowMap); | |
shadow.size = 2048; | |
shadow.power = 200; | |
shadow.blur.radius= 0; | |
shadow.bias *= 0.1; | |
shadow.color.set(0.7, 0.7, 0.7); | |
s3d.camera.zNear = 1; | |
s3d.camera.zFar = 100; | |
new h3d.scene.CameraController(5, s3d).loadFromCamera(); | |
onResize(); | |
} | |
override function onResize() { | |
} | |
override function update(dt:Float) { | |
// obj.rotate(0, 0, 0.12 * dt); | |
} | |
static function main() { | |
hxd.Res.initEmbed(); | |
new HeapsDrag(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment