[Type1]
ChildList = Box0_0 # Box17_0 # Box0_17 # Box17_17
I build an object by using childList, when I use orxObject_SetRotation() to update the degree of the object, then it's rotate on the first object's center..
the way I can figure out, is I create a fake center object as the first one, but it's still annoy that you must calculate the center's position, if there any method to set the new Object's rotation center ?
Comments
I didn't get much sleep last night and it's not helping me using my brain today!
As a rule, all objects apply scale, position and rotation to their pivot (which is the transformation center).
So in your example, let's say Type1 as its pivot at the center and Box0_0 has a position of (100, 0, 0) and also a center pivot.
By default, Box0_0 will have its center 100 pixels to the right of Type1's center. When applying a CW rotation of 90 degrees on Type1, Box0_0's center is now 100 pixels below Type1's center. Both object are also visually displayed with a 90 degrees CW rotation.
I admire you as you always work in such a passion. And it seems you don't sleep over 6 or 8 hours a day usually. I am a sleepy guy, and I always sleep 9-12hours a day :P
I want to write tetris using orx, and the first problem is how I generate different shape.
I use matrix objects to make this.As you can see :
I have 8 basic boxes (they have different position value) , and I choose the need ones( blue in the picture), then I define the Type as :
[Type1]
ChildList = Box0_0 # Box17_0 # Box0_17 # Box17_17
According to what you said, the Type1 has it's own pivot? Can I change it to fit my shape? May be I am not describe clearly, I attached an runtime animation for you, hope this can make this problem clearly.
I'm sure your way of life concerning the amount of sleep is far healthier than mine!
Thanks for all the details, I think I understand all of it now.
Well, to reply to the first question, Type1 can only have a pivot if it has a graphic (as a pivot without a graphic wouldn't be helpful). In your case, it's not exactly the issue.
The thing is that you want to reuse the exact same boxes from your grid for all the tetrominoes (the shapes).
However those tetrominoes don't have the same center (for the square, it's right in the middle of the 4 blocks, on the intersection, whereas for the T, it's in the middle of the junction block).
And you're right, the best way to do that if you want to only use the same blocks would be to add an intermediate object only so that it defines the missing translation you need to move the center of transformation from the grid origin to wherever it needs to be.
Let's say you use the origin as the bottom left corner of your grid, assuming all your block have a centered pivot and that a block size is X, the block 0_0 would have a position of (0.5X, -0.5X), the block 1_0, (1.5X, -0.5X), etc...
Then when definining your tetromino you would have:
[Type1]
ChildList = Type1FakeCenter
[Type1FakeCenter]
Position = translation needed to bring the center from the bottom left grid to where it needs to be
ChildList = list of the blocks used
All this should work fine in theory. However, if you're doing a tetris on a grid (like the traditional one), if you want to support 4 rotations per tetromino, a rotation might not be enough.
For example, if you want to rotate the N (or Z) tetromino, it's rotation center needs to be place on the middle of an edge, and not at the middle of a piece. That is if you want that Rotation0 = Rotation180 and Rotation90 = Rotation270.
But if your center of rotation is there, the position of your tetromino won't be aligned with the grid when you rotate. Not sure if what I'm writing is clear.
This can easily be solved by having both a rotation & a translation when "rotating" the tetromino. But I'm sure you're already aware of that.
So in the end, yes, with a fixed grid and fixed blocks, you need an intermediate object to carry on the translation of your virtual center of tetromino.
the bottom left corner is (0, 0, 0), I set the fake center as (X, -X, 0) ( X for the box edge length), but it's seems rotating to point (-0.5X, 0.5X, 0) ... I am not sure how the object define though ChildList.And how SetRotation() works
I define object like this :
[Type1] ; square..
ChildList = Type1FakeCenter
[Type1FakeCenter]
Position = (17.0, -17.0, 0.0)
ChildList = Box0_0 # Box17_0 # Box0_17 # Box17_17
I am afraid I have to do the rotation to every object by my own code.
if I use grid to do tetris, I maintain a data structure holding the current grid status ,and update the Object position by the grid status every CLOCK time. This seems not the orx way to do such things. What I expected is I do the rotation (transform ) of the tetrominoes using orx object function. And handle the tetrominoes and border collision by event. if I use the grid way, seems it's became a hard code program without game engine support.
So the problem became to how to make a object with component objects( the childlist seems just associate them together when collision happened every object will effect independently), or how can I make a irregular sharp object ( I saw Mesh type in Spawner tutorial may fit my requirement , but I haven't figure out how it works, I will try it tomorrow. ).
It's seems a baisc problem in game programming, unfortunately I have no experience in game development : ( Sorry.
So, if you still want to go with the grid, let's put (0, 0) at the top left corner, this will be easier as it's the same coordinate system as traditional 2D graphics.
Also, if you set a center pivot for your blocks, you'll have to subtract this value from your fake center. I sugget you don't use a centered pivot for clarity sake.
Here come the blocks, we assume X is the block length.
So far so good!
Let's now define our tetromino and it's fake pivot.
We'll make the tetromino T. According to your first drawing, it's rotation center is (1.5X, 2.5X).
This means the position of the Fake Center has to be the opposite of this vector.
And here you go, if you rotate TetrominoT, you'll see that all the blocks rotate at the correct place. You can even add the property AngularVelocity = 90 in [TetrominoT] for an automated test.
Now, if you had your block with a center pivot (Pivot = center), you would have (X, 2X) for the rotation center instead will leads you to a Position = (-X, -2X, 0).
As I told you earlier, if you're using a grid, not for handling the object, but for your logic (to know when a line is full), you might want to dissociate the rotation center from the translation center, or apply a rotation AND a translation every time you change the orientation of a tetromino. But as I don't know your logic code, maybe you don't need that.
Let me know if there's still something confusing. To sum it up, when having a hierarchy of objects, every child is expressed in its parent coordinate system, this way they're bound together and modifying a parent also modify its children.
You're right, it's just that I'm still used to use a grid for writing a Tetris game.
Lately I've been working on a puzzle game, based on a grid, so I handle my logic with a grid but all objects are handled orx style, with animations and FX to have smooth moves without having to write more than a single line of code.
That was a right choice of yours. However, if you want each Tetromino based on a monolithic graphic object, you can define its shape using the mesh property. However all parts have to be convex, so you might need more than one part to define some tetrominoes (like the T or the S/Z). If you need an example, in tutorial #11 I'm using a body with multiple mesh parts for the orx logo that collides with the particles.
No worries, feel free to ask anything you'd like, that's why the forums exist!
As I stay in school this summer, it's time to go home for a while next week , hoping I can make something soon before I go home. Anyway I will continue my development after I returning from home.
As for Mushroom Stew, it includes Scroll, a C++ layer written on top of orx that aims to bring easier management + level editing.
The version packed with Mushroom Stew isn't compatible with the SVN version of orx. If you need a newer version, just let me know!
Sorry for the delay in my replies lately, but I'm preparing to move to the US and it's quite time consuming...