For my first project I want to create 3d menu with sprites as buttons.
http://www.soulsurfer.pl/menu.html
For this I have create the object... ect. To move camera around I m using this function:
CODE
function camRotate(){
if (this.pad_mc.hitTest(_root._xmouse , _root._ymouse, true)) {
// do what you want it to do when the mouse rolls over
running = true;
} else {
// do what you want in to do when the mouse rolls out
running = false;
}
if( running ){ // Move only if running == true
pozx = pozx - p*(_xmouse-Stage.width/2)/120;
pozy = pozy - p*(_ymouse-Stage.height/2)/80;
}else{
pozx = pozx - p*(_xmouse-Stage.width/2)/2000;
pozy = pozy - p*(_ymouse-Stage.height/2)/1000;
}
var _rad:Number = 500;
var phi = pozx * (Math.PI / 180);
var theta = pozy * (Math.PI / 180);
var y = p * _rad * Math.sin(theta);
var z = _rad * Math.cos(theta) * Math.cos(phi);
var x = p * _rad * Math.cos(theta) * Math.sin(phi);
if( ok and ((y >= 499) or (y <= -499))){
//replace button positions
p = p*-1;
op = 0;
ok = false;
var tempTrans = vZ1;
vZ1 = vZ2;
vZ2 = tempTrans;
var tempTrans = vZ6;
vZ6 = vZ4;
vZ4 = tempTrans;
var tempTrans = vZ5;
vZ5 = vZ3
vZ3 = tempTrans;
trans1.translateVector(vZ1);
trans2.translateVector(vZ2);
trans3.translateVector(vZ3);
trans4.translateVector(vZ4);
trans5.translateVector(vZ5);
trans6.translateVector(vZ6);
}
if(op > 8){
ok = true;
}
//we are moving
world.render();
cam.setPosition( x, y, z );
cam.lookAt(0,0,0);
op++;
}
if (this.pad_mc.hitTest(_root._xmouse , _root._ymouse, true)) {
// do what you want it to do when the mouse rolls over
running = true;
} else {
// do what you want in to do when the mouse rolls out
running = false;
}
if( running ){ // Move only if running == true
pozx = pozx - p*(_xmouse-Stage.width/2)/120;
pozy = pozy - p*(_ymouse-Stage.height/2)/80;
}else{
pozx = pozx - p*(_xmouse-Stage.width/2)/2000;
pozy = pozy - p*(_ymouse-Stage.height/2)/1000;
}
var _rad:Number = 500;
var phi = pozx * (Math.PI / 180);
var theta = pozy * (Math.PI / 180);
var y = p * _rad * Math.sin(theta);
var z = _rad * Math.cos(theta) * Math.cos(phi);
var x = p * _rad * Math.cos(theta) * Math.sin(phi);
if( ok and ((y >= 499) or (y <= -499))){
//replace button positions
p = p*-1;
op = 0;
ok = false;
var tempTrans = vZ1;
vZ1 = vZ2;
vZ2 = tempTrans;
var tempTrans = vZ6;
vZ6 = vZ4;
vZ4 = tempTrans;
var tempTrans = vZ5;
vZ5 = vZ3
vZ3 = tempTrans;
trans1.translateVector(vZ1);
trans2.translateVector(vZ2);
trans3.translateVector(vZ3);
trans4.translateVector(vZ4);
trans5.translateVector(vZ5);
trans6.translateVector(vZ6);
}
if(op > 8){
ok = true;
}
//we are moving
world.render();
cam.setPosition( x, y, z );
cam.lookAt(0,0,0);
op++;
}
The problem is in point when the camera gets to y=500 point, as we know it wont go any further and show the object from other side. Thats why I m using the p to make the movement reverse and flip the object. It almost ok, but you can see when it is happening and it doesn't look good. Do you have any ideas how to improve the rotation of this menu.
Thanks !