• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Rotate an image in 3D space?

Community Beginner ,
Jun 28, 2010 Jun 28, 2010

Copy link to clipboard

Copied

I've asked this question a couple places, and so far no one's been able to give me an answer. Hopefully someone here will be able to help me.

I have an image that I want to rotate in 3D space when you move the mouse. This seems easy enough, and I have it mostly working. The problem is, it seems like Flash's 3D camera isn't oriented towards the image. The image is inside a MovieClip so that the center of the image is at 0,0 in the MovieClip, and the MovieClip is located at stageWidth/2,stageHeight/2 -- so it's in the centre of the stage. But if you move the image backwards in z-space, the image doesn't look like it's scaling down, which is what you'd expect -- since it's moving away from the camera -- but instead, it moves up and to the left as it moves backwards.

This is my code:

package {

import flash.display.*;

import flash.events.*;

import flash.net.*;

import flash.geom.Matrix;

import flash.geom.Point;

import flash.text.TextField;

public class Rotation extends MovieClip {

private var loader:Loader;

private var photo:Sprite;

private var display_txt:TextField;

public function Rotation():void {

stage.align = StageAlign.TOP_LEFT;

stage.scaleMode = StageScaleMode.NO_SCALE;

loader = new Loader();

photo = new Sprite();

display_txt = new TextField();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, initListener);

loader.load(new URLRequest("./images/dan.jpg"));

photo.addChild(loader)

addEventListener(Event.ENTER_FRAME, loop);

}

private function initListener (e:Event):void {

addChild(photo);

addChild(display_txt);

loader.x = 0 - (loader.width / 2);

loader.y = 0 - (loader.height / 2);

photo.x = (stage.stageWidth / 2);

photo.y = (stage.stageHeight / 2);

photo.z = 800;

}

private function loop(e:Event):void {

     display_txt.text = String(photo.rotationY);

     photo.rotationY = ((mouseX / stage.stageWidth) * 90)  - 45;

}

}

}

I've also uploaded my AS and resulting SWF here, so you can see the problem in action.

Does anyone know why the camera isn't oriented towards stageWidth/2,stageHeight/2? How do I make the image move directly away from the camera in z-space? Or am I just stupid for not giving up and trying to learn PaperVision?

TOPICS
ActionScript

Views

2.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2010 Jun 28, 2010

Copy link to clipboard

Copied

increase its z parameter if you want it to move away from the viewer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 28, 2010 Jun 28, 2010

Copy link to clipboard

Copied

As you can see from my code, I do -- I gave it a z position of 800. But that doesn't move it directly away from the viewer -- it moves it up and to the left. You can see the result here: http://andcuriouser.com/sandbox/rotation/Rotation.swf.

When the picture has a z-position of 0, it's in the centre of the window. Here, with a z-position of 800, it's no longer in the centre.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2010 Jun 28, 2010

Copy link to clipboard

Copied

do you see any problem in the flash test environment?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 28, 2010 Jun 28, 2010

Copy link to clipboard

Copied

I'm not sure what you mean by "Flash test environment". The project is being compiled straight from the ActionScript, and the SWF is the direct output from that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2010 Jun 28, 2010

Copy link to clipboard

Copied

are you coding in the flash ide?


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 28, 2010 Jun 28, 2010

Copy link to clipboard

Copied

No, I'm compiling it from the ActionScript with MXMLC -- but the results from Flash and Flex should be identical.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2010 Jun 30, 2010

Copy link to clipboard

Copied

Sorry, I need to bump. Has really no one ever had success rotating an image in 3D?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2010 Jun 30, 2010

Copy link to clipboard

Copied

LATEST

i have but i don't use flex so i can't help you with that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines