Collision Between 3d and 2D Objects AS3 - actionscript-3

I'm working on a augmented reality project using FLARtoolkit that need a collision between 3D between 2D objects in AS3. Im using papervision3d and away3d for 3d engine,
My 2d object is a circle and my 3d object is 3d model.
I have try different methods, but to no avail.
Those methods are
Using hitTestObject() on 3d model. Result = impilcit coercion
Using hitTestPoint() on 3d model. Result = cant get the correct model coordinate
I can't get the correct coordinate because the base of coordinate of my model is from marker, and the base of coordinate of my circle is from stage.
Oh yeah, and i try to make a 2D box with same position with my model for collision.
But the coordinate never get right.
Anyone can point me out ways to do collision between 2 different objects in different coordinate ?
Color tracking or anything ?
I appreciate any response, thank you.

Related

Constrain facemesh to 3D object in SparkAR

I am trying to constrain a facemesh to a 3D object so that it will rotate around the surface of the 3D object in response to the face tracker instead of moving off to the side. Currently, the facemesh is a child of the cylinder, but is not attached to it in a way that would rotate around the cylinder surface.
Currently, I am attempting to use the bounding box patch to determine the area to clamp the face mesh to. So far, the mesh is related to the 3D object bounding box, but will not constrain to its surface. Adjustment to the clamp patch variables will move the face mesh within the space, but not constrain it either.
The answer is much simpler than I first attempted. Using the patch editor:
Unpack the 3D rotation from the facefinder.
take the from range from the X and Y positions
look at the maximum and minimum ranges of the face tracker rotation/position values to set To and From Ranges
create a null object and make it a child of the stationary 3D object
make the face mesh a child of the null object
connect the output of the face tracker's rotation/position to the rotation/position value of the null object.

Libgdx get the model direction/front vector

I have a model instance and I rotated it after translated. Is there any way to get my model direction/front vector from my model? How?
The short answer is: no.
A model (instance) is not aware of its direction or which side of it is front. In other words, even if you haven't rotated or translated your model, then you still couldn't get the direction/front vector from your model.
However, if you know the direction/front vector when it is not rotated then you could easily rotate that vector just like your model. So, if the "direction" of your unrotated model is pointing towards the x-axis then the rotated front vector would be:
Vector3 direction = new Vector3(1, 0, 0).rot(modelInstance.tranform);

Primitives and sprites Z index in Cocos2D-x 3.0 is not consistent?

I have two layers. Each layer has a primitive drawing in it with OpenGL like this:
void Layer1::drawPolygon()
{
glLineWidth(1);
DrawPrimitives::setDrawColor4B(255,255,255,255);
DrawPrimitives::setPointSize(1);
// Anti-Aliased
glEnable(GL_LINE_SMOOTH);
// filled poly
glLineWidth(1);
Point filledVertices[] = { Point(10,120), Point(50,120), Point(50,170), Point(25,200), Point(10,170) };
DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) );
}
When I addChild these layers to a scene and set Z orders 1 and 2, I see that I can bring one primitive on top of another and vice versa - when I exchange the Z order values. The strange things start when I addChild a sprite into one of these layers. If I addChild a sprite, then sprite lays on top of the primitive of that layer, and not only that layer. Even if the layer has smaller Z index, anyway its sprite is on top of other layer's primitive, while its primitive is below the other primitive shape - as was expected. Is this OK? How I should understand this? What if I want to draw primitives on top of all sprites?
EDIT:
I could manipulate their order, but not drawing order, with the following:
CCDirector::getInstance()->setDepthTest(true);
myLayer->setVertexZ(-1);
But I don't understand why sprites in a layer with smaller Z order are being drawn later than the primitives of the layer with bigger Z order. In other words, seems that all the primitives from all the layers is being drawn according to their order, then the same is being done for the sprites.
Due to the new multithreader renderer on cocos2d-x 3.0, drawing with primitives requires a different approach. Take a look at my reply at this thread:
https://stackoverflow.com/a/22724319/1468700
I believe there is a bug in cocos2d-x V3 beta 2 that makes primitive drawing always appear below all layers.
It is fixed (I understand) in V3.0 RC
This is incorrect - there is no bug (I was mislead by other posts - my apologies).
See the post below for a link explaining what needs to happen to get primitives to draw in the 'right' z-order.
The summary is that all drawing operations are added to a queue in the game loop, then the queue processed - so you need to add your primitive drawing into the queue rather than drawing immediately.

Away3d Camera Path

How to know the coordinates of the path if you know the azimuthal angle. I wanna move my camera around an object in away 3d.
Move camera in Spherical coordinate system by Interpolating from starting azimuthal angle to target - it will be your trajectory.
You can convert from\to Cartesian coordinate system to retrive\pass current coordinate to away3d renderer.
You all so may want to use non-linear camera acceleration(for more realistic feel) it can be implemented with Bézier curves
PS. I will be thankful if your publish you realisation because i will need this functional in my next project. You will save me a lot of time :)
Or just use translation and rotation methods that camera inherits from Object3D it's all covered in Away3D example projects. Allso Away3D has path helper package

What is "drawing context" exactly? What is the role of getcontext() method?

What is getContext() method and what is drawing context exactly? why we always pass the string 2d to the getContext() method?
Context is a way to choose what you are going to do with your canvas.
For moment you can use getContext for 2d (2dcanvas) or for 3d (WebGL).
HTML5 Specification say's about getContext :
"Returns an object that exposes an API for drawing on the canvas. The first argument specifies the desired API. Subsequent arguments are handled by that API."
You can find specifications for each API there :
https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext
It is also good to know that "webgl" is the correct name for API but for moment, as it is experimental you should use "experimental-webgl" to start creating WebGL content
In Computer graphics, a drawing context is an abstraction (class/object) that encapsulates how you are going to draw stuff.
At a 100k foot level, computer graphics is about converting drawing commands to pixels (image). How you go from commands to pixels is what the graphics pipeline is all about (very broad and deep subject). A drawing context exposes drawing methods and properties to achieve this.
Example of a drawing commands: drawLine, drawPath, drawRect (you get the idea).
Example of drawing properties: fill color, stroke color, stroke style, font size, clipping region etc
In the context (pardon the pun) of web, you have two drawing contexts - canvas for 2d drawing and and webgl for 3d drawing.