Original Post
Hi,
i have a little Question about Ray Picking - I use the Flash API "Stage3D" where it is hard to find informations.
After a lot of searching i dosn't find a stage solution so i adapt some opengl/directX Code, but i don't became it work.
Here is my current code:
[source lang="java"] var mX:Number = -1 + (p.x / winSize.x) * 2;
var mY:Number = 1 - (p.y / winSize.y) * 2;
var farPos:Vector3D = new Vector3D( mX, mY, 1.0, 1.0 );
var nearPos:Vector3D = new Vector3D( mX, mY, 0.0, 1.0 );
var mt:Matrix3D = new Matrix3D();
mt.append(getProjection());
mt.append(getView());
mt.invert();
nearPos = mt.transformVector(nearPos);
farPos = mt.transformVector(farPos);
nearPos.scaleBy(1.0 / nearPos.w);
farPos.scaleBy(1.0 / farPos.w);
var Dir:Vector3D = farPos.subtract(nearPos);
Dir.normalize();
trace(nearPos.toString());
ray = new CRay(nearPos, Dir);
return ray;[/source]
But when i click on some boxes on the screen the intersection never happens, or on the wrong element(everytime the same
)....
So now i don't have any idea what is wrong and i'm very frustrated. Can here somebody help me out? That were soo great!
p.s. sorry for my bad english.
Greetz
Stimpy
i have a little Question about Ray Picking - I use the Flash API "Stage3D" where it is hard to find informations.
After a lot of searching i dosn't find a stage solution so i adapt some opengl/directX Code, but i don't became it work.
Here is my current code:
[source lang="java"] var mX:Number = -1 + (p.x / winSize.x) * 2;
var mY:Number = 1 - (p.y / winSize.y) * 2;
var farPos:Vector3D = new Vector3D( mX, mY, 1.0, 1.0 );
var nearPos:Vector3D = new Vector3D( mX, mY, 0.0, 1.0 );
var mt:Matrix3D = new Matrix3D();
mt.append(getProjection());
mt.append(getView());
mt.invert();
nearPos = mt.transformVector(nearPos);
farPos = mt.transformVector(farPos);
nearPos.scaleBy(1.0 / nearPos.w);
farPos.scaleBy(1.0 / farPos.w);
var Dir:Vector3D = farPos.subtract(nearPos);
Dir.normalize();
trace(nearPos.toString());
ray = new CRay(nearPos, Dir);
return ray;[/source]
But when i click on some boxes on the screen the intersection never happens, or on the wrong element(everytime the same
So now i don't have any idea what is wrong and i'm very frustrated. Can here somebody help me out? That were soo great!
p.s. sorry for my bad english.
Greetz
Stimpy