Showing posts with label Away3D Tutorial. Show all posts
Showing posts with label Away3D Tutorial. Show all posts

Wednesday, June 30, 2010

Real Position of Object from Inside a Moving Container in Away3DLite Tutorial

Real Position of a Sphere from Inside a Moving Container in Away3DLite Tutorial (Feb 24th 2010)

The position of an object inside a container is in the local space of the container. Using the current sceneMatrix transformation of the container parent on the contained primitive's position yeilds the absolute position to use as a reference in the overall scene.


This is how to get the real position of a sphere from inside a moving container:

myBasketball.x = PlayerContainer.sceneMatrix3D.transformVector(mySphere.position).x;

myBasketball.y = PlayerContainer.sceneMatrix3D.transformVector(mySphere.position).y;

myBasketball.z = PlayerContainer.sceneMatrix3D.transformVector(mySphere.position).z;


As you can image, if you place a 3D object at some point in an Objectcontainer like a sphere, then you can use these points for reference in placing things like other models, explosions or calculation of any distance from that reference sphere. Do note that a sphere is visible and handy for a while but a non-rendered object with a position member variable itself will do.

All kinds of things are possible using this!

Best regards.

Away3D Tutorial: Accessing Object Group Index from Bounding Box Collision Detection

Accessing Object Group Index from Bounding Box (Feb 24th 2010)

When the collision of a bounding box occurs in my 3D game I wanted to know which character the bounding box belongs too. The "character" is really an obectContainer in an array of objectContainers. Each element in the array represents one character and each element is an obectContainer containing the character model, bounding box and any accessories so they all travel together. The bounding box collision is therefore representative of it's parent's obectContainer collision "with another obectContainer" (which also has a bounding box).

So, I supposed the simplest way to do this would be to edit the Cube primitive class to contain an integer index to use to access other objects in the same group via their respective arrays.

I put the following into the Cube6.as Cube class file:

...
/**
* Creates a 3d Cube primitive.
*/
public class Cube6 extends AbstractPrimitive
{
private var _width:Number = 100;
private var _height:Number = 100;
private var _depth:Number = 100;
private var _segmentsW:int = 1;
private var _segmentsH:int = 1;
private var _segmentsD:int = 1;
private var _pixelBorder:int = 1;

//CGG Added
//Accessing Object Group Index from Bounding Box (Feb 24th 2010)
//Edit the Cube primitive class to contain an integer index to use to access other objects in the same
//group via their respective arrays including obectContainer and mesh(es).
public var groupIndex:int;

...


The var groupIndex:int; is public so we can set and get ourselves. Not ideal but it works.

Correcting Z-Sorting in Away3DLite: Away3D AS3 Tutorial

Away3DLite Tutorial (Feb 18th 2010)

I have a model of an indoor space and the characters feet are showing under the floor at time so I tried my hand at resolving the issue and this was it:

Here in AS3 we change the sort type using the relevant class which has recently changed names from MeshSortType.

Ex: stadium.sortType = SortType.BACK;

This was enough to correct the Z-sorting of the indoor model in Away3DLite. It may very well be the same thing you need to do in the Away3D library. I'm not sure. Unless you are using the new BSP tree in Away3D you will probably need this line.

Either this information was hard to get to or I'm just not very good at finding it but it took some time and trial.

Good luck on your games!