A Flash Developer Resource Site

# Thread: Generative 3D structure; compound rotation/translation

1. ## Generative 3D structure; compound rotation/translation

Hello,

This is a bit more of a conceptual/mathsy problem than a technical one, but I am working in Flash CS4 and I thought this would be a good place to ask.

What I'm trying to do, essentially, is generate a 3D structure of square panels (subclassed sprites), connected perpendicularly at their edges. There are two connection parameters I'm planning to allow (and pick randomly between these on generation):
1. connecting edge:- top; bottom; left; or right
2. joining angle:- outer (where the connecting panel points away from the previous one; 270 degrees from the front); and inner (where the connecting panel points towards the screen from the previous one; 90 degrees from the front).

Defining where the subsequent panel should be placed from the initial one is quite straightforward. As an example, if the first panel is facing front on the stage, and the next connecting panel is selected to make a left-outer join, then (assuming panels have a registration point in the centre) that new panel should have the following transformations applied after being placed on top of the original:
• Add 90 to the .rotationY property (so it faces the left of the stage)
• Subtract half the panel's width from the .x property (so that it moves left to the edge of the first panel)
• Add half the panel's width to the .z property (so that its rightmost edge touches the leftmost edge of the original panel, perpendicularly)

I can quite easily define 8 transformation patterns like that for my 8 combined joining types, and use Math.random with Math.floor to pick one from an array. The problem I then have is that those defined transformations are relative to the starting point of the first panel, and so I can't use them repeatedly from their original state. Once the subsequent panels have been rotated, the set of 8 no longer apply.

So! I imagine related problems have been tackled before, and I was hoping for some general advice - not a free solution to the problem. If you know of any reading I could do on combining the 3D transformations in this way, that would be really helpful. I just don't know where to start!

(Just to be transparent, I first posted this in the 3D board of flashmove.com, not previously noticing that there was a 3D board here. It's been up for a few days with no replies, and that site has now mysteriously vanished for the past 24rs. I'll cross-post any replies though.)

2. If you use a math.random and then plan on building from it. and in 3D... connecting the two will be a chore. Your pieces will have to know of the other pieces and build from that if you want an interconnected structure.

To be honest, this reminds me of the "seed" type of structures we used to do. Random on the first, then within a gamut for the rest. So that meant each start was random, but the rest was capable of starting a structure.

But that was the generative stuff I had done with the open plugin architecture for Signwave's Auto-Illustrator.

A lot of times, you'll see that your random should be only limited to a set, then parameters of degrees of difference(s) within parameters then chosen from there might be a logical step. Just some ideas. It's been a while since I've tackled any generative design though to be honest.

3. If I understand you correctly, you want the subsequent (2nd tier+) panels to be making their decisions based on their progenitor's coordinate space, rather than based on the global coordinate space, right?

Why can't you just copy the parent's coordinates and rotation to the new panel first, and then have your preset rotations add/subtract from that? That would be the easiest way...

A harder, but possibly more rewarding way (depending on your goal here) would be to set up a data object that mirrored the parent-child relationships, and tracked each one's coordinate space relative to its parent. That would let you create a function that could take any object and translate its coordinates to global coordinates.

4. Thanks a lot for your replies.

Gerbick, I hadn't previously considered making a set of 'scripted' connections, and it is an option, but as the structures will be of arbitrary length depending on the data given, I'll need to allow them to loop around the first orientation. There's also the issue of people beginning to recognise the particular pattern from the set being used, and it would be a lot of work to supply parameters for enough sequences that no-one noticed the repetition.

As for actually performing the construction, I have a function within the parent sprite that iterates through the array of panels/children, which will set the position of one, then pass back the position of the last panel moved on each iteration, so that the subsequent pass can be made relative to the last. I think that's what you were referring to by saying that each piece had to know about the others

(I hadn't previously heard of AutoIllustrator but it seems like generative art with that or Processing would be a pretty nice thing to get into.)

Joshstrike, I think you have a good idea of the particular problem, but I either don't quite understand your first suggestion, or it's like something I've tried before, which wasn't successful. I've made a diagram to help explain the difficulty

Ok, so this is an illustration of an attempt at a making a 'right-outer' join twice sequentially, from a front-facing first panel. I'll explain each subsection.
A: The 1st and 2nd panels connected correctly. From the position of the 1st, the 2nd panel was rotated -90 degrees around the y-axis, moved +x for 1/2 its width, then +z also for 1/2 width. The eight equivalent movements are easily defined in these terms.
B: The intended location of the 3rd panel, if the movement could have been repeated relative to the 2nd panel. (This is the kind of thing I'm unable to code.)
C: The location of the 3rd panel, if the movements from the first to the 2nd are simply repeated. (This does not represent a 'right-outer' join, and is not what I want.)

(I should probably mention, my goal isn't to create a bunch of squares that say 'sup?' on them! This was just for illustration.)

Unless I have misunderstood what you were suggesting, joshstrike, just moving the subsequent panel into position and then applying the transformation again results in misplacement.

Depending on how I interpret your wording, you maybe think that all subsequent panels are the display-children of the previous? That's not the case in what I'm doing; there's a single parent sprite containing all panels, and they're of equal rank. But in your second suggestion, you may be right that I could simulate that sort of relationship to take advantage of the globalToLocal()/localToGlobal() methods to use my relative placement function in each of the new object positions. I'll keep thinking about that.

The other idea I've had since starting this was to construct the sequence in reverse order, starting with the last panel in the set, and pair each of my 8 transformations with a single correcting rotation. Using the Matrix3D object, I ought to be able to spin each of the panels made so far around a common point, so that the last-arranged panel is in the starting position (and all previous ones are connected in place). I hope that makes sense! It's so much harder to visualise things in more than two dimensions.

5. maybe check out some of these

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap