This is G o o g l e's cache of http://www.flashsandy.org/forum/lofiversion/index.php/t21.html as retrieved on 25 Jul 2007 03:23:27 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:KTxrmnSQIBgJ:www.flashsandy.org/forum/lofiversion/index.php/t21.html+site:www.flashsandy.org+index.php&hl=en&ct=clnk&cd=104


Google is neither affiliated with the authors of this page nor responsible for its content.
These terms only appear in links pointing to this page: index php

Full Version: Camera rotation
damo
Bonjour à tous,
J'ai une camera dans ma scene que j'ai placée à
cam.setPosition(0, 30, -200);
Je voudrais la faire tourner, en utilisant le clavier, autour de la verticale qui passe par 0,0,0
En gros j'ai un objet au centre de l'univers et je voudrais faire tourner la camera autour.
J'ai essayé de travailler avec
World3D.getInstance().getCurrentCamera().rotateAxis(0,10,0,1);
mais j'ai un peu de mal.

Une idée ?

Merci
Seraf
Yo,
il faut que tu saches la distance entre ta cam et ton origine

distance= Math.sqrt((CamX*CamX)+(CamY*CamY));
circlePlace=0;
la camera va donc tourner sur un cercle il faut determiner ou elle va se placer

//onMotion
circlePlace ++;
cam.setPosition(Math.cos(circlePlace*pi/360)*distance,CamZ,Math.sin(circlePlace*pi/360)*distance);

tu vas peut etre besoin d'utiliser lookAt sur la camera wink.gif
kiroukou
Hi, (I'll answer in english cauz this post might be interessting for a lot of people).
If you want to rotate the camera around a specific point this is the good way to do it.

But I would like to have your opinion about the camera transformations :
Would that be interessting to control the camera transformations as we do for the objects?
The bad things I can see is that it will make more lines on code to do something simple, and it will be a bit slower.

The good thig is that you would be able to do very complex transformations. Should be quite powerfull.

What is your opinion about that?
damo
thx a lot guys.
I think the camera transformation is great actually.
But it will be interesting if we have more traformations like a rotation around another vector.



J'avais pas compris à quoi servait rotateAxis. Donc effectivement il faut que j'utilise un deplacement le long d'un cercle et apres soit un lookAt, soit une rotation.

Dans la doc kiroukou nous met en garde sur l'utilisation de lookAt, je vais donc essayer une simple rotation.
kiroukou
Yes damo, the lookAt method can have a strange behaviour sometimes. I've tested it but not enought to feel 100% proof about it.

but in 95% of situations, it should work fine smile.gif You can test it, because compute yourself the correct rotation axis/value can be a bit hard if you're not fond of maths biggrin.gif
damo
It seems to work well.

But i have another problems.
this is my code :
CODE
import sandy.core.data.*;
import sandy.core.group.*;
import sandy.primitive.*;
import sandy.view.*;
import sandy.core.*;
import sandy.skin.*;
import sandy.util.*;
import sandy.core.transform.*;
import sandy.events.*;
import flash.display.BitmapData;

//skins
var maTexture:BitmapData = BitmapData.loadBitmap("map.jpg");
var maTexture2:BitmapData = BitmapData.loadBitmap("soleil.jpg");
var maSkin:TextureSkin = new TextureSkin(maTexture);
var skinSoleil:TextureSkin = new TextureSkin(maTexture2);

function init( Void ):Void
{
    // screen creation, the object where objects will be displayed.
    var screen:ClipScreen = new ClipScreen( this.createEmptyMovieClip('screen', 1), 600, 600 );
    // we create our camera
    var cam:Camera3D = new Camera3D( 700, screen);
    // we move the camera backward to be able to see the object placed at 0,0,0
    cam.setPosition(0, 30, -200);
    // we add the camera to the world
    World3D.getInstance().addCamera( cam );
    // we create the root node.
    var bg:Group = new Group();
    // and set it as the root node of the world.
    World3D.getInstance().setRootGroup( bg );
    // and we lauch the scene creation
    createScene( bg );
    // and now that everything is created, we can launch the world rendering.
    World3D.getInstance().render();
    //Ecouteur de clavier
    unEcouteur = new Object();
    unEcouteur.onKeyDown = worldRotate;
    Key.addListener(unEcouteur);    
}

function createScene( bg:Group ):Void
{
    // We create our object. It is a cube of 50 pixels
    var maSphere:Sphere = new Sphere( 5, 5, "tri" );
    var monSoleil:Sphere = new Sphere( 10, 5, "tri" );
    maSphere.setSkin(maSkin);
    monSoleil.setSkin(skinSoleil);
    var tg1:TransformGroup = new TransformGroup ();
    var tg2:TransformGroup = new TransformGroup ();
    var translation:Transform3D = new Transform3D ();
    var translation2:Transform3D = new Transform3D ();
    translation.translate (0, 45, 0);
    tg1.addChild (maSphere);
    tg1.setTransform (translation);
    translation2.translate (38, 15, -17);
    tg2.setTransform (translation2);
    tg2.addChild (monSoleil);
    // Now we simply link the Object leaf to the root node, and finish the tree creation
    bg.addChild( tg1);
    bg.addChild( tg2);
    bg.addChild( createGrille());
}
function createGrille():TransformGroup{
    var grilleSkin:MixedSkin = new MixedSkin(0x00FF00,20,0x00FF00,100,1);
    var toto:TransformGroup = new TransformGroup ();
    var tata:Plane3D = new Plane3D(100,100,4,"quad");
    tata.setSkin(grilleSkin);
    toto.addChild(tata);
    return toto;
}
// We lauch the animation creation.
init();
//Animation au clavier
var circlePos:Number=0;
var distance:Number = 200;
var pi:Number = Math.PI;

function worldRotate():Void {
    if(Key.isDown(Key.LEFT)) {
        var CamY:Number = World3D.getInstance().getCurrentCamera().getPosition().y;
        // On tourne vers la gauche
        circlePos -=10;
        World3D.getInstance().getCurrentCamera().setPosition(Math.cos(circlePos*pi/360)*distance,CamY,Math.sin(circlePos*pi/360)*distance);        
        World3D.getInstance().getCurrentCamera().lookAt(0,0,0);
        World3D.getInstance().render();        
    }
    if(Key.isDown(Key.RIGHT)) {
        var CamY:Number = World3D.getInstance().getCurrentCamera().getPosition().y;
        // On tourne vers la droite
        trace(circlePos);
        circlePos +=10;
        World3D.getInstance().getCurrentCamera().setPosition(Math.cos(circlePos*pi/360)*distance,CamY,Math.sin(circlePos*pi/360)*distance);
        World3D.getInstance().getCurrentCamera().lookAt(0,0,0);
        World3D.getInstance().render();
    }
}


I dont know why it's so slowly. In fact its more and more slowly after each seconds.
Any idea ?


Je sais pas pourquoi c'est aussi lent et surtout pourquoi c'est de plus en plus lent.
kiroukou
Rapidly, you must NOT call world3D render several times!!
(I need to add a test thought to avoid that problem)

If the problems is still here, I'll look at it when I go back home.

++ wink.gif
damo
Thx smile.gif
I have delete the World3D.render() from my code and it seems to work well.
kiroukou
Super, me voilà rassuré ^^
Bonne continuation
Mnyh
hi everybody!
did anyone of you allready try to do this camera-movement not only 2d, but 3d.
the code from seraf for 2d rotation is
CODE
circlePlace ++;
cam.setPosition(Math.cos(circlePlace*pi/360)*distance,CamZ,Math.sin(circlePlace*pi/360)*distance);
cam.lookAt(0, 0, 0);


i want not only a circle but two cicles, one vertical and one horizontal.
my try looks like that, but doesn't work sad.gif i have circlePos as one angle and circlePosy for the other.
CODE
if (Math.cos(circlePosy*pi/360)*distance < 0)  {
  z = Math.sin(circlePos*pi/360)*distance+Math.cos(circlePosy*pi/360)*distance; } else {
  z = Math.sin(circlePos*pi/360)*distance-Math.cos(circlePosy*pi/360)*distance; }
cam.setPosition(Math.cos(circlePos*pi/360)*distance, Math.sin(circlePosy*pi/360)*distance, z);
cam.lookAt(0, 0, 0);


i think i made a mistake but i can't find it. i was looking for a solution for some hours sad.gif
but maybe it's the lookAt-function which causes problems?

or will it be better to rotate the box itself?
geertings, mnyh
kiroukou
Just a fast look at your code and a first thing that seems wieird is the pi value. Are you sure that your pi variable is equal to 2*Math.PI ? Because it should be.

Otherwise it is really simpler to make your object rotating around the camera thanks to the Matrix classes I've made, and espacially RotationInterpolators.

But it does mean the same thing only if you have a single object to display.
++

Mnyh
pi is set somewhere more early in the code, that's right.
it works with 2d if i set the y-value to 200.
okay. maybe i give it a try with RotationInterpolators wink.gif
thanx so far
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2007 Invision Power Services, Inc.