Re: [問題] flex匯入3D後的碰撞
我把我的程式碼貼上來
我是用flex builder 3
cowdae.as
package
{
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.cameras.*;
import org.papervision3d.materials.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.parsers.Collada;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.*;
import org.papervision3d.view.Viewport3D;
public class cowdae extends Sprite
{
public var viewport:Viewport3D;
public var renderer:BasicRenderEngine;
public var default_scene:Scene3D;
public var default_camera:Camera3D; a
public var cow:DisplayObject3D = new DisplayObject3D();
public var cow1:DisplayObject3D = new DisplayObject3D();
public var sphere2:DisplayObject3D = new DisplayObject3D();
[Embed(source = "sphere.DAE", mimeType = "application/octet-stream")]
private var COW_dae:Class;
public function cowdae()
{
init();
cow1 = new Collada("sphere.dae"); 這是我在3dsMax中建好的模型轉成dae
cow1.moveDown(100);
cow1.scale = 0.1;
default_scene.addChild(cow1);
var sphere2:DisplayObject3D = default_scene.addChild(new Sphere);
if(sphere2.hitTestObject(cow1))
{
trace("碰撞1")
}
}
private function init(vpWidth:Number = 800, vpHeight:Number = 600):void {
initPapervision(vpWidth, vpHeight);
initEvents();
}
protected function initPapervision(vpWidth:Number = 800, vpHeight:Number = 600):void {
viewport = new Viewport3D(800,600);
addChild(viewport);
renderer = new BasicRenderEngine();
default_scene = new Scene3D();
default_camera = new Camera3D();
}
protected function initEvents():void {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
protected function onEnterFrame( ThisEvent:Event ):void {
renderer.renderScene(default_scene, default_camera, viewport);
}
public function up():void{
cow1.y += 100;
}
public function left():void{
cow1.x -= 100;
}
public function down():void{
cow1.y -= 100;
}
public function right():void{
cow1.x += 100;
}
public function testl():void{
cow1.z -= 100;
}
public function testr():void{
cow1.z += 100;
}
public function collision():void{
if(sphere2.hitTestObject(cow1))
{
trace("碰撞二")
}
}
}
}
cow.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
<mx:Script>
<![CDATA[
private var aaa:cowdae = new cowdae();
private function init():void{
this.PV3DArea.addChild(this.aaa);
}
]]>
</mx:Script>
<mx:Canvas width="100%" height="80%" backgroundColor="white">
<mx:UIComponent id="PV3DArea" width="100%" height="100%"/>
</mx:Canvas>
<mx:ApplicationControlBar>
<mx:Button label="Front" click="this.aaa.left()"/>
<mx:Button label="Back" click="this.aaa.right()"/>
<mx:Button label="Up" click="this.aaa.up()"/>
<mx:Button label="Down" click="this.aaa.down()"/>
<mx:Button label="Left" click="this.aaa.testl()"/>
<mx:Button label="Right" click="this.aaa.testr()"/>
<mx:Button label="Collision" click="this.aaa.collision()"/>
</mx:ApplicationControlBar>
</mx:Application>
目前的問題是
我直接debug後 會偵測到碰撞的產生 會出現 碰撞一
可是當我再度按下collision的button後 卻偵測不到碰撞的產生
請大家指點一下
非常感謝
※ 引述《forgot75421 (伏加特I》之銘言:
: 各位好
: 我想要請問
: 當我在3DsMAX中建好模型轉成DAE(物件1&2)後,再到flex中顯現出來(已經成功匯入)
: 這時,若我想要讓這兩個物件碰撞時會觸發某件事,例如物件變色之類的
: 請問這可以做到嗎?? 可以給我一點方向嗎??
: (我有用DisplayObject3D.hitTestObject(DisplayObject3D)去試 可是一直失敗
: 不知是否還有其他方法)
: 非常感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.161.164.42
推
05/10 21:04, , 1F
05/10 21:04, 1F
→
05/10 21:04, , 2F
05/10 21:04, 2F
→
05/10 21:05, , 3F
05/10 21:05, 3F
→
05/10 21:05, , 4F
05/10 21:05, 4F
→
05/10 21:05, , 5F
05/10 21:05, 5F
→
05/10 21:06, , 6F
05/10 21:06, 6F
→
05/10 21:06, , 7F
05/10 21:06, 7F
→
05/10 21:06, , 8F
05/10 21:06, 8F
→
05/10 23:53, , 9F
05/10 23:53, 9F
→
05/10 23:54, , 10F
05/10 23:54, 10F
→
05/11 11:25, , 11F
05/11 11:25, 11F
推
05/11 14:22, , 12F
05/11 14:22, 12F
→
05/11 14:22, , 13F
05/11 14:22, 13F
→
05/11 14:22, , 14F
05/11 14:22, 14F
→
05/11 14:23, , 15F
05/11 14:23, 15F
→
05/11 15:38, , 16F
05/11 15:38, 16F
→
05/11 15:38, , 17F
05/11 15:38, 17F
→
05/11 15:38, , 18F
05/11 15:38, 18F
推
05/11 15:45, , 19F
05/11 15:45, 19F
→
05/11 15:45, , 20F
05/11 15:45, 20F
→
05/11 15:45, , 21F
05/11 15:45, 21F
→
05/11 15:46, , 22F
05/11 15:46, 22F
→
05/11 15:47, , 23F
05/11 15:47, 23F
→
05/11 15:49, , 24F
05/11 15:49, 24F
→
05/11 16:05, , 25F
05/11 16:05, 25F
推
05/11 16:09, , 26F
05/11 16:09, 26F
→
05/11 16:35, , 27F
05/11 16:35, 27F
→
05/11 16:35, , 28F
05/11 16:35, 28F
→
05/11 16:39, , 29F
05/11 16:39, 29F
推
05/11 23:05, , 30F
05/11 23:05, 30F
→
05/11 23:05, , 31F
05/11 23:05, 31F
→
05/11 23:13, , 32F
05/11 23:13, 32F
→
05/11 23:13, , 33F
05/11 23:13, 33F
→
05/11 23:13, , 34F
05/11 23:13, 34F
→
05/12 17:10, , 35F
05/12 17:10, 35F
討論串 (同標題文章)