PDA

Click to See Complete Forum and Search --> : Trig Question



Tempest_design
08-27-2002, 02:15 PM
ok I've just begun to mess with making a psudo 3d engine.
The engine takes the x,y of the camera object and the x,y of an icon object (both invisible) and translates it to a third scale object.

Here is the code inside the third "visible" object

onClipEvent(enterFrame){

Radians = Math.atan2((_root.camera._y-_root.block._y), (_root.camera._x-_root.block._x));
_root.point_dir = Math.round(Radians*180/Math.PI);
directionz=_root.point_dir+(360-_root.camera._rotation)/2-90;
directionz-=800-((directionz)*5.1);

_x=directionz;

}

( problem ) I realize Flashs coord system goes from 0-180 & -180-0 degrees (translated from Radians)

I'm used to doing this with a 360 degree rotation.
And so if the camera object is <_root.block._y then everything goes reverse. I've fixed this to some extent by saying:

onClipEvent(enterFrame){
if(_root.camera._y>_root.block._y){
Radians = Math.atan2((_root.camera._y-_root.block._y), (_root.camera._x-_root.block._x));
_root.point_dir = Math.round(Radians*180/Math.PI);
directionz=_root.point_dir+(360-_root.arrow._rotation)/2-90;
directionz-=800-((directionz)*5.1);
}else{
Radians = Math.atan2((_root.block._y-_root.camera._y), (_root.camera._x-_root.block._x));
_root.point_dir = Math.round(Radians*180/Math.PI);
directionz=_root.point_dir+(360-_root.arrow._rotation)/2-90;
directionz-=800-((directionz)*5.1);


_x=directionz;}

}

But it's still not quite right. In fact sometimes for some reason the view is all backwards!

Anyways does anyone have a means to translate a 360 degree rotation? ( 0-360 degrees )

BlinkOk
08-27-2002, 07:43 PM
hi Tempest_design,
i have no idea about manually calculating rotation so i use a technique that takes advantage of the localToGlobal()/globalToLocal() methods. this is what i do;
1. i have a camera and object mc (just like yours both invisible).
2. when i want to rotation or move the camera i do just that. i adjust _rotation (of the camera) to rotate and _x/_y to move.
3. then when i want to calculate my 3d point i use globalToLocal() to translate the position of my object from
the main stage to the camera mc and bingo! all the rotation is done for me in one simple step.
here is .swf that explains the principle (87k no preloader);
check out the relativeCamera() function in the car mc;
http://www.nlc.net.au/~oceana/games/camera.swf
http://www.nlc.net.au/~oceana/games/camera.zip
here are some samples that use the same principle;
(the camera tracking/following is so easy with this technique)
http://www.nlc.net.au/~oceana/games/3ddemo1.html
http://www.nlc.net.au/~oceana/games/3ddemo1.fla
http://www.nlc.net.au/~oceana/games/area7.html
http://www.nlc.net.au/~oceana/games/area7.fla
ps: one other tip with the 3d engine. if your scaling objects always have a top point and a bottom point. then
you can convert both points from 3d to 2d and the difference gives you the height of the object.
hope this helps
BlinkOk
[Edited by BlinkOk on 08-27-2002 at 11:45 PM]

howard54321
09-04-2002, 05:13 PM
adjustedAngle = (angle*(angle>0))+((angle+360)*(angle<0));

this makes it 0 to 360

not 90 to -270 or whatever it is.

is that what you mean.

howard