need a litle help on trigonometry

Software: Away3D 4.x

killerPigeon, Newbie
Posted: 03 May 2012 01:27 PM   Total Posts: 1

Hi,

I just finished my multiplayer gateway so i want to build a multiplayer game. I ‘m usin Away3d 4 but have some problems:

My first problem is about trigonometry.
I want to fallow an object with camera form a distance and height (for example 100px from behind and 50px from top). That object can rotate in 3
axis. For a quick solution i made a 3D container and put both camera and object in it and rotatin and movin container instead of weichle

like that:

private function init():void{
...
_container = new ObjectContainer3D();
_container.addChild(_camera);
_camera.100;
view.scene.addChild(_container);
...
}

private function onResourceComplete(e:LoaderEvent):void {
 
...
 
_container.addChild(_loader);
 ...
}

private function onEnterFrame(event:Event):void {
 
...
 
_container.rotationY += ((mouseX - (stage.width /2) )* 0.004);
 
_container.rotationX += ((mouseY - (stage.height /2) )* 0.004);
 
_container.rotationZ += ((mouseX - (stage.width /2) )* 0.001);
 
_container.moveForward(currentSpeed);

 
// _camera.x = ;
 // _camera.y = ;
 // _camera.z = ;

 
_camera.lookAt(_loader.position);
 ...

but this is not enaught. I want to add easing animations to camera on bounce, crash or any another event. I need to samehow calculate camera’s

position from object’s position and angles. i found some simples.

var targetX:Number car.Math.sin(car.rotationZ)*cameraDistance;
var 
targetY:Number car.Math.cos(car.rotationZ)*cameraDistance;
var 
targetZRotation:Number car.rotationZ+Math.PI;
 
camera.-= (camera.targetX)*.2;
camera.-= (camera.targetY)*.2;
camera.rotationZ -= (camera.rotationZ targetZRotation)*.2

in this simple car only rotates on z axis but my weichle will rotate x,y and z axis together. Then i found a formula for 3D rotation

x1 cos(angleZ) * sin(angleZ) * y;
y1 cos(angleZ) * sin(angleZ) * x;
x1 cos(angleY) * sin(angleY) * z;
z1 cos(angleY) * sin(angleY) * x;
y1 cos(angleX) * sin(angleX) * z;
z1 cos(angleX) * sin(angleX) * y

but my trigonometry not good enaught to correct it to add distance and height ( i did’t even understand what it says).

as a 2nd problem ofcourse my players need to have their name on their weichles and looks like on version 4 Away3D don’t have a common 3DText support. i found a simple on forum

var newText:TextField = new TextField();
newText.width 300;
newText.text "My dynamic text";

var 
txtForm:TextFormat = new TextFormat();
txtForm.color 0xffffff;
txtForm.size 48;
newText.setTextFormat(txtForm);
   
var 
btTxt:BitmapData = new BitmapData(10241024true0x000000);
btTxt.draw(newTextnullnullnullnulltrue);
   
var 
myTxtMat BitmapMaterial = new BitmapMaterial(btTxttruefalsetrue);
   
_board = new Sprite3D(myTxtMat12864); 

but don’t know why i can’t see text anywhere. again for a quick solutin i’m going to add TextFields to directly to my Sprite but can’t find a way to
change 3D vertex of an object in scene to point in stage.

Thanx for any help.

Edit: I mistakely pressed update buton instead of preview. put other half of post

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X