confused about HitTestRenderer

Software: Away3D 4.x

shin10, Newbie
Posted: 03 February 2012 03:57 PM   Total Posts: 5

Hi guys,

I am new to away3d and first steps were very promising but now I am running into troubles.
What I try to do is creating lens flares to the sun in my scene. Therefore I would like to know if some object is between my camera and the pivot of my sun. I thought the HitTestRenderer is exactly what I need for this. So I wrote a little class to achieve this but unfortunately it always returns null.

What confuses me is that HitTestRenderer is working fine in the Mouse3DManager. I hope you could point out to me what I have been missing.

package away3d.core.managers
{
 import away3d
.arcane;
 
import away3d.containers.View3D;
 
import away3d.core.render.HitTestRenderer;
 
import away3d.core.base.IRenderable;
 
import away3d.core.traverse.EntityCollector;
 
import flash.geom.Point;
 
 use namespace 
arcane;
 public class 
HitTest3DManager
 {
  
private var _view:View3D;
  private var 
_hitTestRenderer:HitTestRenderer;
  private var 
_collector:EntityCollector
  
  
public function HitTest3DManager(view View3D)
  
{
   _view 
view;
   
_hitTestRenderer = new HitTestRenderer(_view);
   
_collector _view.entityCollector;
  
}
  
  
public function getObjectAtPosition(position:Point):IRenderable {
   _hitTestRenderer
.update(position._view.widthposition._view.height_collector);
   return 
_hitTestRenderer.hitRenderable;
  
}
 }

in my main application:

//after away3D init
_hitTest = new HitTest3DManager(view);
...
// onEnterFrame
var pos:Point view.project(sun.position);
trace_hitTest.getObjectAtPosition(pos) );// always null?! 

kind regards

Michael

 

   

Avatar
Alexander Seifert, Moderator
Posted: 04 February 2012 02:42 PM   Total Posts: 129   [ # 1 ]

Regarding the Lens Flare ... this is something I always wanted to play around with but never really got to it.
How do you do it? =)

Cheers!
Alex

 

 Signature 
signature_image

http://www.deltastrike.org

   

shin10, Newbie
Posted: 05 February 2012 03:29 AM   Total Posts: 5   [ # 2 ]

Hi Alex,

right now my code is a mess. Maybe I can find some time tomorrow to clean it up and prepare a little example.

Since these are my first two weeks in Away3D (to be honest, in any 3D coding) there might be much better solutions. I am looking forward to your opinion.

so long

Michael

 

   

shin10, Newbie
Posted: 05 February 2012 09:48 PM   Total Posts: 5   [ # 3 ]

Hi,

sorry no complete example code but at least I cleaned the two necessary classes. (see the zip file below)
It is not completely done yet. I only tested PerspectiveLens & DirectionalLight ... anything else maybe later if it is possible to detect Objects between camera and lightsource. Otherwise it would not make sense anyway.

btw: Is there a possibility to create layers or prevent clipping for specified objects/materials or anything like that? Right now I try to set the position as near as possible to the frustrum - could cause display errors. How are you guys handling stuff like that? Layers would be really great, e. g. for HUDs.

>> live example (fp ~5MB / 11.2 beta)
use the mouseWheel to change the fieldOfView

3 simple steps:
embed some bitmaps:

[Embed(source="embedded_assets/lensFlares/sunSphere.png")]
  
private var matSunSpehereBitmap:Class;
  
[Embed(source="embedded_assets/lensFlares/flare1.png")]
  
private var matSunFlare1Bitmap:Class;
  
[Embed(source="embedded_assets/lensFlares/flare2.png")]
  
private var matSunFlare2Bitmap:Class;
  
[Embed(source="embedded_assets/lensFlares/flare3.png")]
  
private var matSunFlare3Bitmap:Class;
  
[Embed(source="embedded_assets/lensFlares/flare4.png")]
  
private var matSunFlare4Bitmap:Class;
  
[Embed(source="embedded_assets/lensFlares/flareRing.png")]
  
private var matSunFlareRingBitmap:Class;
  
[Embed(source="embedded_assets/lensFlares/sunGlow.png")]
  
private var matSunGlowBitmap:Class;
  
[Embed(source="embedded_assets/lensFlares/sunStar.png")]
  
private var matSunStarBitmap:Class;
  
[Embed(source="embedded_assets/lensFlares/flareStreak.png")]
  
private var matSunFlareStreakBitmap:Class; 

initiate the controller (I use about 40 flares):

import de.flintfabrik.away3d4.fx.LensFlares.LensFlare3DManager;
 
import de.flintfabrik.away3d4.fx.LensFlares.LensFlare;
...
lensFlare3DManager = new LensFlare3DManager(viewsundirectionalLight1.direction);
   
//lens flares
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare1Bitmap().bitmapData,   -0.3 1.0));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare2Bitmap().bitmapData,    0.7 1.0 ));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare3Bitmap().bitmapData,   -1.5 1.0 ));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare4Bitmap().bitmapData,    0.2 1.0 ));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare1Bitmap().bitmapData,    1.3 1.0 ));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare2Bitmap().bitmapData,    1.2 1.0 ));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare3Bitmap().bitmapData,    0.651.0));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare4Bitmap().bitmapData,   0.8 1.0 ));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlareRingBitmap().bitmapData,  1.7 1.0 ));
   
//sun
   
lensFlare3DManager.addChild(new LensFlare(new matSunGlowBitmap().bitmapData,   0.0 1.0 ));
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlareStreakBitmap().bitmapData,  0.0 2.0.5 ));
   
lensFlare3DManager.addChild(new LensFlare(new matSunStarBitmap().bitmapData,   0.0 2.0 ));
   
//extreme
   
lensFlare3DManager.addChild(new LensFlare(new matSunFlare1Bitmap().bitmapData,   -50.0 10.0));
   
lensFlare3DManager.addChild(new LensFlare(new matSunGlowBitmap().bitmapData,    50.0 10.0));
   
   
//additional random lens flares
   
var flareMaps:Array = new matSunFlare1Bitmap().bitmapData,
         new 
matSunFlare2Bitmap().bitmapData,
         new 
matSunFlare3Bitmap().bitmapData,
         new 
matSunFlare4Bitmap().bitmapData
        ]
;
   for (var 
i:int 020i++ ) {
    lensFlare3DManager
.addChild(
     new 
LensFlare(
      
flareMaps[ Math.floorMath.random() * flareMaps.length],
      
Math.random() * 10 ,
      
Math.random() * 0.5,
      
Math.random() *.25 .25
     
)
    );
   
}
   
for (010i++ ) {
    lensFlare3DManager
.addChild(
     new 
LensFlare(
      
flareMaps[ Math.floorMath.random() * flareMaps.length],
      
Math.random() * ,
      
Math.random() * 1.5,
      
Math.random() *.25 .25
     
)
    );
   

onEnterFrame:

LensFlare3DManager.updateAll(); 

That is all

Regards

Michael

ps: I killed my apostorphe key - just in case somebody has been wondering.

edit: dispose method error fixed

 

File Attachments
lensflare.zip  (File Size: 512KB - Downloads: 219)
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X