Senocular 3d tutorial problem

Hello everyone!

Sorry, I realise the title of this post is misleading there’s nothing wrong with the tutorial, it’s one of the best tutorials I’ve ever seen! It’s found here: http://www.kirupa.com/developer/actionscript/3dexplore.htm

The problem… is actually with me :bored:… Here’s my code:



this.createEmptyMovieClip("Surfaces",1);

Surfaces._x = 275;
Surfaces._y = 200;

var surfacenum:Number = 0;
var obj = new Array(255);

CameraProp = new Object();

CameraProp.x = 20;
CameraProp.y = 0;
CameraProp.z = 35;
CameraProp.rotation = 0;
CameraProp.upAngle = 0;
CameraProp.focallength = 300;

create3dobj = function(type,posx,posy,posz,sizex,sizey)
{
    if (type == 1) // forward facing
    {
    obj[surfacenum] = new Array
                                  (new Array((posx + sizex/2), (posy + sizey/2), (posz), 0, 0), //p1
                                   new Array((posx - sizex/2), (posy + sizey/2), (posz), 0, 0), //p2
                                   new Array((posx - sizex/2), (posy - sizey/2), (posz), 0, 0), //p3
                                   new Array((posx + sizex/2), (posy - sizey/2), (posz), 0, 0));//p4
    }
    if (type == 2) // side facing
    {
    obj[surfacenum] = new Array
                                 (new Array((posx), (posy + sizey/2), (posz+ sizex/2), 0, 0), //p1
                                  new Array((posx), (posy + sizey/2), (posz- sizex/2), 0, 0), //p2
                                   new Array((posx), (posy - sizey/2), (posz- sizex/2), 0, 0), //p3
                                   new Array((posx), (posy - sizey/2), (posz+ sizex/2), 0, 0)); //p4 
    }
    Surfaces.createEmptyMovieClip("surface_"+surfacenum.toString(),posz);

    surfacenum++;
}
create3dobj(1,20,0,30,10,10);
create3dobj(2,100,-20,50,10,30);
create3dobj(1,20,0,0,10,10);

this.onEnterFrame= function() {
    var scaleRatio, x,y,z,tx,ty,tz;
    for (var i = 0; i < surfacenum; i++)
    {
        for (var j = 0; j < 4; j++)
        {
                x = obj*[j][0]-CameraProp.x;
                y = obj*[j][1]-CameraProp.y;
                z = obj*[j][2]-CameraProp.z;
                
    // rotation on the y axis
    var angle = CameraProp.rotation;
    tx = Math.cos(angle)*x - Math.sin(angle)*z;
    tz = Math.sin(angle)*x + Math.cos(angle)*z;
    x = tx;
    z = tz;

    // rotation around x axis
    angle = CameraProp.upAngle;
    ty = Math.cos(angle)*y - Math.sin(angle)*z;
    tz = Math.sin(angle)*y + Math.cos(angle)*z;
    y = ty;
    z = tz; 
    
        scaleRatio = CameraProp.focallength/(CameraProp.focallength + z);
        obj*[j][3] = (x)*scaleRatio; 
        obj*[j][4] = (y)*scaleRatio;
        }
        
        Surfaces["surface_"+i.toString()].clear();
        Surfaces["surface_"+i.toString()].lineStyle(2,0x000000,100);

        Surfaces["surface_"+i.toString()].moveTo(obj*[0][3],obj*[0][4]);
        
        Surfaces["surface_"+i.toString()].lineTo(obj*[0][3],obj*[0][4]);
        Surfaces["surface_"+i.toString()].lineTo(obj*[1][3],obj*[1][4]);
        Surfaces["surface_"+i.toString()].lineTo(obj*[2][3],obj*[2][4]);
        Surfaces["surface_"+i.toString()].lineTo(obj*[3][3],obj*[3][4]);
        Surfaces["surface_"+i.toString()].lineTo(obj*[0][3],obj*[0][4]);
        
    }
        
    if (Key.isDown(Key.RIGHT)) CameraProp.rotation += .05;
    if (Key.isDown(Key.LEFT)) CameraProp.rotation -= .05;
    
    var movement = 0;
    if (Key.isDown(Key.UP)) movement += 10;
    if (Key.isDown(Key.DOWN)) movement -= 10;
    
    CameraProp.x += Math.sin(CameraProp.rotation)*movement;
    CameraProp.z += Math.cos(CameraProp.rotation)*movement;
}



What the problem is, is that I want everything to rotate around the camera. Like in a first person view (the way we see things in real life)… And it just isn’t doing that…What am I doing wrong? It’s probably something really dumb. Please help?