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);
Related
I wish to use the "intersects" (from Starling) to create a collision, but i don't know how to convert my Quad "player" and my Quad "block" to Rectangles.
Can someone help?
Quad contains a getBounds public method that returns a new rectangle (or an updated one if passed in on the second param), so:
var playerRect:Rectangle = quadPlayer.getBounds(this);
var blockRect:Rectangle = blockPlayer.getBounds(this);
if (playerRect.intersects(blockRect)) {
trace("Collision!");
}
Now, I am using this as I do not know your display list hierarchy and this do not know which coordinate system your quads are in, so adjust accordingly.
http://doc.starling-framework.org/current/starling/display/DisplayObject.html
Transforming coordinates
Within the display tree, each object has its own local coordinate system. If you rotate a container, you rotate that coordinate system - and thus all the children of the container.
Sometimes you need to know where a certain point lies relative to another coordinate system. That's the purpose of the method getTransformationMatrix. It will create a matrix that represents the transformation of a point in one coordinate system to another.
http://doc.starling-framework.org/current/starling/display/Quad.html
getBounds(targetSpace:DisplayObject, out:Rectangle = null):Rectangle
[override] Returns a rectangle that completely encloses the object as it appears in another coordinate system.
i am using blender to create my models, and loading them into Libgdx, if i create them with the Origin in the center of the model like below and then use this code to create the rigid body, all works fine
Vector3 hescoWallHalfExtents = new Vector3(hescoWall.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);
however if i place the bottom of the model level with the ground like this
then the btRigidbody is offset like this
is there an obvious way that i can offset the height of the rigidbody?
many thanks.
Spriggsy
The center (origin) of the rigid body is the same as the center of mass and therefor an important property for the physics simulation. You could "move" this center using a btCompoundShape if you like, but this will also influence the physics simulation and therefore probably won't give you satisfying results.
Alternatively, you could compensate for the difference of physics origin and visual origin in your btMotionState. For example by setting ModelInstance#transform to the provided worldTransform multiplied by the a Matrix4 instance which contains the offset (use Matrix4#translate for example).
However, this is probably just making it more complex than it needs to be. You could say that the real question is why you want offset the center of model compared to the body? For example, in you second image the center of the model appears to be same as the in the first image. You only moved the Node, basically indicating that you want to provide an initial value for the ModelInstance#transform member. You can achieve this by instantiating the ModelInstance as follows:
modelInstance = new ModelInstance(model, "coneNode", true);
Replace "coneNode" with the name of the node as created it in your modeling application. The last (true) argument tells the ModelInstance to set its transform member to the transformation you've given it in the modeling application. If needed, you can call modelInstance.transform.translate(x, y, z); or modelInstance.transform.trn(x, y, z); to move the modelInstance relative to this transformation.
A more in-depth explanation of this can be found here: http://blog.xoppa.com/loading-a-scene-with-libgdx/
Note that this only works if you're using .g3db or .g3dj files (e.g. using fbx-conv) created from a file format that supports node transformations (e.g. .fbx, but not .obj)
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.
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.
I'm new to Geotools. I am developing a simple application that shows a map and I would like to dynamically place a bitmap or vector symbol on it (for example to show where the current position is, like in navigation systems).
Now, what I've done already is:
showing a map given one or more shapefile.
center the map on the last inserted position.
add shapes to new layers when needed.
What I need to do is to create an overlay with images at given coordinates on the map area (to be clear, I don't want to generate a raster layer on disk, I just want to paint on the screen).
My guess is that I have to somehow directly use the Graphics2D instance inside JMapPane, is that correct? In this case how can I convert from the geographic coordinates to pixel coordinates on the drawing pane? Or are there some geotools functions/classes that I should be looking for?
Thank you.
Answering myself, since I found the solution.
I did it by extending class org.geotools.map.DirectLayer, which provides a way to define a custom layer by extending its draw(Graphics2D, MapContent) method. Graphic elements are placed at the correct coordinates by using the worldToScreen affine transform provided by geotools. For example, to define a Point2D placed at the current position given real-world coordinates:
AffineTransform worldToScreen = viewport.getWorldToScreen();
Point2D worldPoint = new Point2D.Double(currentPosition.x, currentPosition.y);
Point2D screenPoint = worldToScreen.transform(worldPoint, null);
Once the draw() method is defined, just instantiate and add as a layer to your MapContent instance.