var initHeight:Number = onScreenHeight / Math.cos(rotationAngle)
But it does not work. I guess I need to include fieldOfView in calculation, but don’t have any idea how 
Btw, projectionCenter is set to top-center of bitmap (if it matters).
golle saidI don’t know what exactly you are trying do or what your code is , but you can apply this sample on bitmap also (CS4 )
I have bitmap that I want to rotate on x axis using rotateX (not animation, just initial rotation). When I do that, actual height of bitmap on screen is of course smaller then initial height. What I want to do is to calculate initial height based on rotation angle, so when bitmap is rotated on-screen height is always the same. I thought it can be done with simple trig calculationvar initHeight:Number = onScreenHeight / Math.cos(rotationAngle)But it does not work. I guess I need to include fieldOfView in calculation, but don’t have any idea how
Btw, projectionCenter is set to top-center of bitmap (if it matters).
public class Main extends Sprite {
private var sp:Sprite;
private var golle:Sprite;
public function Main() {
graphics.beginFill(0xff0000);
graphics.drawRect(75, 75, 250, 250);
sp = new Sprite();
sp.x = 200;
sp.y = 200;
addChild(sp);
golle = new Sprite();
golle.graphics.beginFill(0xffff00);
golle.graphics.drawRect(-125, -125, 250, 250);
golle.graphics.endFill();
sp.addChild(golle);
sp.rotationX=120
//for animation
//addEventListener(Event.ENTER_FRAME, RunMeBaby);
}
// private function RunMeBaby(e:Event):void{
// sp.rotationX++;
// }
}
}
- Community Superstar
- Item was Featured
- Author was Featured
- Has been a member for 5-6 years
- Won a Competition
- Sold between 50 000 and 100 000 dollars
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- Europe
can’t you just keep his height in a variable or something? .. or reset the transformations applied to it>read the height + keep the value for future use>apply back initial transformations?
Thanks Tsafi, but that’s not what I need. I’ll try to be more clear: when you rotate bitmap, bounding box is changing, so if original height of bitmap is 200px, when rotated on x axis for let say PI/3, bounding box height is not 200 but … well something else
I thought it should be 200*Math.cos(PI/3)=100, but it isn’t 
What I need is to set height of bitmap, so when rotated on X, its bounding box height is 200px
wickedpixel said
can’t you just keep his height in a variable or something? .. or reset the transformations applied to it>read the height + keep the value for future use>apply back initial transformations?
No, you misunderstood me also, damn I’m so bad In explaining things 
here is example of what I try to do, hope it is more clear now 
This is stupid way, kinda waste CPU , and only work with rectangle shape DisplayObjects…... but if you really need get bound before apply 3D transform to your target DisplayObject…
var source:Bitmap;
// ... scripts for build source
var sourceBound:Rectangle = source.getBounds(source);
var shape:Shape = new Shape();
var g:Graphics = shape.graphics;
g.beginFill(0);
g.drawRect(sourceBound.x, sourceBound.y, sourceBound.width, sourceBound.height);
g.endFill();
shape.transform.matrix3D = source.transform.matrix3D.clone();
shape.rotationX = 30;
if (shape.height > someValue)
{
source.transform.matrix3D = shape.transform.matrix3D.clone();
}
What about a while loop?
while(boundingBox < 200){
height++;
}
Intensive as well, but might do the trick..
@savorks
Sorry, I don’t understand your code, how do I get height from that? I just need formula to calculate object height, for given bounding box height and rotation angle.
@Emroni
I thought about that too
but would like to avoid it. I really did not expect this to be such a problem, but I lost all day on this and still did not find solution 
Anyway, I wasted to much time already on this, so I give up, back to 2d world 
Thanks everybody for trying to help me
I think it’s possible to calculate it, see also more on http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS36223081-8938-4b45-BB89-F1F8B1A52E4E.html and on http://stackoverflow.com/questions/2422516/actionscript-3-3d-with-fieldofview
But it seems complex on first sight. I supose you need to take into the calculation your projectionCenter point values, fieldOfView value and rotationX value, and using those recalculate the height of your items.
More pratical to me seems to simply 3D ‘apply’ them to you needs and then use a getBounds method to check the resulting size and apply a rescale of scaleX/Y (on a parent MovieClip you’ll need to create for the item)
Hope that makes sense
Well, if Flash Player can calculate size of bounding box, I guess it is possible to do reverse calculation
I just didn’t imagine it is so complicated 
I gave up on this already, but anyway thanks for links patrick, it might be useful sometime in future.
