# 3D Spinning Logo Help

**URL:** <https://forum.kirupa.com/t/3d-spinning-logo-help/238097>\
**Category:** flash\
**Created:** [September 7, 2007, 6:22am UTC](https://forum.kirupa.com/t/3d-spinning-logo-help/238097 "2007-09-07T06:22:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben2](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@Ben2](https://forum.kirupa.com/u/Ben2)\
**Post date:** [September 7, 2007, 6:22am UTC](https://forum.kirupa.com/t/3d-spinning-logo-help/238097/1 "2007-09-07T06:22:35Z")

</div>

Using the 3D in Flash tutorial on this website I’ve created a 3D spinning object. It works fine, but I really really need some help on this one.

I’ve modeled a logo for someone, but he needs it to do this: Click on it to spin it around, and let go to reset it back to the original state.

Here’s my code:

```auto
var origX:Number = Stage.width/2;
var origY:Number = Stage.height/2;
var haveControl:Boolean = true;
var focalLength:Number = 100;
var speedNum:Number = 0;
var perspecNum:Number = 0;
var accelNum:Number = 1;
var pointsArray:Array = new Array(
    makePoint(0, 0, -10),
    makePoint(60, 0, -10),
    makePoint(60, 20, -10),
    makePoint(20, 20, -10),
    makePoint(20, 60, -10),
    makePoint(0, 60, -10),
    makePoint(0, 0, 10),
    makePoint(60, 0, 10),
    makePoint(60, 20, 10),
    makePoint(20, 20, 10),
    makePoint(20, 60, 10),
    makePoint(0, 60, 10),
    
    makePoint(25, 25, -10),
    makePoint(85, 25, -10),
    makePoint(85, 60, -10),
    makePoint(65, 60, -10),
    makePoint(65, 45, -10),
    makePoint(45, 45, -10),
    makePoint(45, 65, -10),
    makePoint(60, 65, -10),
    makePoint(60, 85, -10),
    makePoint(25, 85, -10),
    makePoint(25, 25, 10),
    makePoint(85, 25, 10),
    makePoint(85, 60, 10),
    makePoint(65, 60, 10),
    makePoint(65, 45, 10),
    makePoint(45, 45, 10),
    makePoint(45, 65, 10),
    makePoint(60, 65, 10),
    makePoint(60, 85, 10),
    makePoint(25, 85, 10)
);

this.createEmptyMovieClip("box", 0);

function makePoint(x:Number, y:Number, z:Number) {
    var pointObj:Object = new Object();
    pointObj.x = x-42.5;
    pointObj.y = y-42.5;
    pointObj.z = z;
    pointObj.origX = pointObj.x;
    pointObj.origY = pointObj.y;
    pointObj.origZ = pointObj.z;
    pointObj.x1 = 0;
    pointObj.y1 = 0;
    pointObj.z1 = 0;
    pointObj.z2 = 0;
    return pointObj;
}

function calcScale(pointObj3D:Object) {
    var pointObj2D:Object = new Object();
    var scaleRatio:Number = focalLength/(focalLength+pointObj3D.z);
    pointObj2D.x = pointObj3D.x*scaleRatio;
    pointObj2D.y = pointObj3D.y*scaleRatio;
    return pointObj2D;
}

box.onPress = function() {
    haveControl = true;
}
box.onRelease = function() {
    haveControl = false;
}

box.onReleaseOutside = function() {
    haveControl = false;
}

box.onEnterFrame = drawBox;
function drawBox() {
    var screenPoints = new Array();
    for (var i:Number = 0; i < pointsArray.length; i++) {
        var thisPoint:Object = pointsArray*;
        var angleX:Number = (_ymouse-origY)*.001;
        var angleY:Number = (_xmouse-origX)*.001;
        var cosX:Number = Math.cos(angleX);
        var sinX:Number = Math.sin(angleX);
        var cosY:Number = Math.cos(angleY);
        var sinY:Number = Math.sin(angleY);
        if(haveControl) {
            thisPoint.x1 = thisPoint.x*cosY-thisPoint.z*sinY;
            thisPoint.z1 = thisPoint.z*cosY+thisPoint.x*sinY;
            thisPoint.y2 = thisPoint.y*cosX-thisPoint.z1*sinX;
            thisPoint.z2 = thisPoint.z1*cosX+thisPoint.y*sinX;
        } else {
            //Reset back to normal
        }
        thisPoint.x = thisPoint.x1;
        thisPoint.z = thisPoint.z2;
        thisPoint.y = thisPoint.y2;
        screenPoints.push(calcScale(thisPoint));
        screenPoints*.x += origX;
        screenPoints*.y += origY;
    }
    this.clear();
    this.lineStyle(1, 0x000000, 100);
    
    this.beginFill(0x000000, 50);
    this.moveTo(screenPoints[0].x, screenPoints[0].y);
    this.lineTo(screenPoints[1].x, screenPoints[1].y);
    this.lineTo(screenPoints[2].x, screenPoints[2].y);
    this.lineTo(screenPoints[3].x, screenPoints[3].y);
    this.lineTo(screenPoints[4].x, screenPoints[4].y);
    this.lineTo(screenPoints[5].x, screenPoints[5].y);
    this.lineTo(screenPoints[0].x, screenPoints[0].y);
    this.endFill();
    this.beginFill(0x000000, 50);
    this.moveTo(screenPoints[6].x, screenPoints[6].y);
    this.lineTo(screenPoints[7].x, screenPoints[7].y);
    this.lineTo(screenPoints[8].x, screenPoints[8].y);
    this.lineTo(screenPoints[9].x, screenPoints[9].y);
    this.lineTo(screenPoints[10].x, screenPoints[10].y);
    this.lineTo(screenPoints[11].x, screenPoints[11].y);
    this.lineTo(screenPoints[6].x, screenPoints[6].y);
    this.endFill();
    
    this.beginFill(0x000000, 50);
    this.moveTo(screenPoints[12].x, screenPoints[12].y);
    this.lineTo(screenPoints[13].x, screenPoints[13].y);
    this.lineTo(screenPoints[14].x, screenPoints[14].y);
    this.lineTo(screenPoints[15].x, screenPoints[15].y);
    this.lineTo(screenPoints[16].x, screenPoints[16].y);
    this.lineTo(screenPoints[17].x, screenPoints[17].y);
    this.lineTo(screenPoints[18].x, screenPoints[18].y);
    this.lineTo(screenPoints[19].x, screenPoints[19].y);
    this.lineTo(screenPoints[20].x, screenPoints[20].y);
    this.lineTo(screenPoints[21].x, screenPoints[21].y);
    this.lineTo(screenPoints[12].x, screenPoints[12].y);
    this.endFill();
    this.beginFill(0x000000, 50);
    this.moveTo(screenPoints[22].x, screenPoints[22].y);
    this.lineTo(screenPoints[23].x, screenPoints[23].y);
    this.lineTo(screenPoints[24].x, screenPoints[24].y);
    this.lineTo(screenPoints[25].x, screenPoints[25].y);
    this.lineTo(screenPoints[26].x, screenPoints[26].y);
    this.lineTo(screenPoints[27].x, screenPoints[27].y);
    this.lineTo(screenPoints[28].x, screenPoints[28].y);
    this.lineTo(screenPoints[29].x, screenPoints[29].y);
    this.lineTo(screenPoints[30].x, screenPoints[30].y);
    this.lineTo(screenPoints[31].x, screenPoints[31].y);
    this.lineTo(screenPoints[22].x, screenPoints[22].y);
    this.endFill();
}

```

If you put that code into your first frame of your flash document (2.0), then you’ll see what it does.

Where it says in the code Reset back to normal, I want the object to spin back to the original state. I’ve tried just easing the points back to their original positions but that ruins the whole 3D element. I’ve tried **everything** I can think of, so I’m completely stuck. If anyone could help me on this one… well, I’d be incredibly grateful!

Thanks in advanced,  
Ben.
