Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position one object based on another that's rotated

I have a set of blocks which could be rotated at any angle. My task is to create an extra block to one side of the set, adjacent to the last block. I'm using Flex/AS3 and openscales. An illustration will be good to explain what I want to achieve. I apologise in advance for the crudeness of my pictures, I only have MS Paint to hand!

Easy extra block

Wrong block

Corre2t block

My current formula for the picture 2 is simply:

block5XPos += block4XPos - block3XPos;
block5YPos += block4YPos - block3YPos;

** Edit **

I cannot work with Display Objects in the usual way i.e. rotate, addChild. I'm restricted to utilising x and y values and having to re-calculate these values.

like image 690
Christopher Grigg Avatar asked Nov 21 '25 15:11

Christopher Grigg


1 Answers

If your solution allows, you could put all your blocks in a parent movieclip, rotate that movieclip. And then just modify the x parameter when you add new blocks to the parent movieclip. This would translate the block along the "local" x axis of the rotated parent.

Pseudocode:

var parent:MovieClip = new MovieClip()
parent.rotation = 45
addChild(parent)

var block1 = new BlockClip()
block1.x = 10
parent.addChild(block1)


var block2 = new BlockClip()
block2.x = 20
parent.addChild(block2)
like image 127
BobbyTables Avatar answered Nov 23 '25 09:11

BobbyTables