object as a children of multiple objects - three.js

Can an object be a child of multiple objects?
A.add( C );
B.add( C ); is valid right?
what happens if I translate B but not A ? Will C move?
Perspective: I have 27 cubes in a 3 X 3 matrix. All the cubes are part of the main cube_group.
I now want to move just the top 9. Can I put them in a separate group and move the group? Will that work?
It's going to be a while, before I try this out, so thought I'd ask in the meantime.

Rubik's cube, hm?
You question is actually similar to this: can a ball be in two different boxes at the same time? What if I would to move one box?
It's not possible (unless it's a ball in a box in a box), neither you have real need to do something like that.
Don't group them at all, just apply centered transformation on the (logical) group of nine pieces.
So, the answer are: "no, it can't" and it's not valid".

Related

What algorithm to use for finding empty areas in 2D?

I have 3d elements (triggers) that spawn content boxes when clicking on them. I am searching for an algorithm that spawns elements in an empty area close to the trigger. A 2d approach might be enough since the content boxes need to face the user.
The spawned content box should neither overlap the trigger object, nor other 3d elements / contentboxes.
Example:
If the trigger is a long vertical tube, the first contentbox might spawn to the left of it, the next one would spawn to the right since the left is already occupied with contentbox 1. The third contentbox might then spawn above/below the first contentbox or if there is other stuff in the way then to the left of the first contentbox.
This should work in realtime, it doesnt have to be the actual closest point but should aim for keeping everything closely together. I assume that this is a problem many people solved before me but somehow I couldnt find sufficient information, maybe I am lacking the correct search terms, I am happy to hear about different approaches, hints & ideas..
Thanks
friday
Try to create a grid on the existed points in the plane or space. This grid could be two perpendicular line on each existed point. After that, create a tree to search on this space. Or just create a kd-tree on these points. Youcan find more about these in computational geometry context.

Collision with .sks Physics bodies at the same level

When I am creating a .sks scene in Xcode, I often need two nodes at the exact same x or y position to create a wall. I add rectangular physics bodies. They both have no friction whatsoever.
When I make a spritenode move over these collision bodies (I am using an impulse to the physics body) it acts as if there is a barrier between the two rectangles and I need to 'push' the node or make it jump to get over a boundary.
As I stated, these nodes are perfectly in line with each other so nodes should be able to flow past them smoothly.
Any suggestions?
If you need any code/pictures I am using, please ask.
Edit: The answer
My problem was the collision platforms were colliding with each other, and so they were slightly pushed out by on the generation of all platforms.
The way to solve is to set these following values on the platforms:
categoryBitMask to 1
collisionBitMask to 4294967294
which basically means they won't collide with each other.
Still new to swift, good to keep learning :P
I have already pointed #abc to the right answer. Just to explain why the masks are at 4294967295:
You can see that this is 32bits (all 1's with that number). Each bit is a different mask, and collisions and category masks look at these, to determine properties such as do they touch/collide. This means you have 32 masks you can make in your game.
If you want to understand how to make masks or combine masks, you can use Bitwise Operators. These operators can let you add masks together using the | (or) bitwise operator, or something similar. Please read the Apple Documentation I linked to.

How to add collision detection in a 2D car game in XNA?

Right, I'm making a 2d car racing game. So far I've got the car moving etc (with a little help of course) and was wondering how do I go about adding collision detection in XNA. I've taken a bumper part (from the whole track), and made it as a separate .png file. And I was thinking of adding a collision detection box around it (so if 'car' hits 'bumper' move back by so and so). How do I add collison detection to the bumper, and integrate it with the car? Thank you!
Try this tutorial: http://create.msdn.com/en-US/education/catalog/tutorial/collision_2d_perpixel
Source code for the tutorial is in Downloads, under the two (ugly) blue boxes.
It seems this would be a lot easier if the cars were always straight--not rotated. If they were rotated you wouldn't be able to use rectangles to help.
If you do, then you could instead have the bumper included in car.png.
Then you could use the coordinates of the car and add certain values to get the length and width of the region for the bumper.
You can then do
Rectangle bumperBoundingBox = new Rectangle
(
(int)X_COORDINATE_OF_CAR,
(int)Y_COORDINATE_OF_CAR,
(int)X_COORDINATE_OF_CAR + WIDTH_OF_BUMPER,
(int)Y_COORDINATE_OF_CAR + HEIGHT_OF_BUMPER
);
Rectangle otherCarBoundingBox = new Rectangle( \* x, y, ... *\ );
bool carIsTouchingBumper = otherCarBoundingBox.Intersects(bumperBoundingBox);
This may not be perfectly perfect, as in the parameters for rectangle might be in a different order or something like that. But once you have it, you can use carIsTouchingBumper and do stuff.
If you want the bumper to be a separate image, you could do the same thing as above, except use the coordinates of the bumper instead. Also you would have to make the bumper follow the car.

Raytracing (LoS) on 3D hex-like tile maps

Greetings,
I'm working on a game project that uses a 3D variant of hexagonal tile maps. Tiles are actually cubes, not hexes, but are laid out just like hexes (because a square can be turned to a cube to extrapolate from 2D to 3D, but there is no 3D version of a hex). Rather than a verbose description, here goes an example of a 4x4x4 map:
(I have highlighted an arbitrary tile (green) and its adjacent tiles (yellow) to help describe how the whole thing is supposed to work; but the adjacency functions are not the issue, that's already solved.)
I have a struct type to represent tiles, and maps are represented as a 3D array of tiles (wrapped in a Map class to add some utility methods, but that's not very relevant).
Each tile is supposed to represent a perfectly cubic space, and they are all exactly the same size. Also, the offset between adjacent "rows" is exactly half the size of a tile.
That's enough context; my question is:
Given the coordinates of two points A and B, how can I generate a list of the tiles (or, rather, their coordinates) that a straight line between A and B would cross?
That would later be used for a variety of purposes, such as determining Line-of-sight, charge path legality, and so on.
BTW, this may be useful: my maps use the (0,0,0) as a reference position. The 'jagging' of the map can be defined as offsetting each tile ((y+z) mod 2) * tileSize/2.0 to the right from the position it'd have on a "sane" cartesian system. For the non-jagged rows, that yields 0; for rows where (y+z) mod 2 is 1, it yields 0.5 tiles.
I'm working on C#4 targeting the .Net Framework 4.0; but I don't really need specific code, just the algorithm to solve the weird geometric/mathematical problem. I have been trying for several days to solve this at no avail; and trying to draw the whole thing on paper to "visualize" it didn't help either :( .
Thanks in advance for any answer
Until one of the clever SOers turns up, here's my dumb solution. I'll explain it in 2D 'cos that makes it easier to explain, but it will generalise to 3D easily enough. I think any attempt to try to work this entirely in cell index space is doomed to failure (though I'll admit it's just what I think and I look forward to being proved wrong).
So you need to define a function to map from cartesian coordinates to cell indices. This is straightforward, if a little tricky. First, decide whether point(0,0) is the bottom left corner of cell(0,0) or the centre, or some other point. Since it makes the explanations easier, I'll go with bottom-left corner. Observe that any point(x,floor(y)==0) maps to cell(floor(x),0). Indeed, any point(x,even(floor(y))) maps to cell(floor(x),floor(y)).
Here, I invent the boolean function even which returns True if its argument is an even integer. I'll use odd next: any point point(x,odd(floor(y)) maps to cell(floor(x-0.5),floor(y)).
Now you have the basics of the recipe for determining lines-of-sight.
You will also need a function to map from cell(m,n) back to a point in cartesian space. That should be straightforward once you have decided where the origin lies.
Now, unless I've misplaced some brackets, I think you are on your way. You'll need to:
decide where in cell(0,0) you position point(0,0); and adjust the function accordingly;
decide where points along the cell boundaries fall; and
generalise this into 3 dimensions.
Depending on the size of the playing field you could store the cartesian coordinates of the cell boundaries in a lookup table (or other data structure), which would probably speed things up.
Perhaps you can avoid all the complex math if you look at your problem in another way:
I see that you only shift your blocks (alternating) along the first axis by half the blocksize. If you split up your blocks along this axis the above example will become (with shifts) an (9x4x4) simple cartesian coordinate system with regular stacked blocks. Now doing the raytracing becomes much more simple and less error prone.

Algorithm for positioning rectangular and randomly sized objects inside a non-rectangular canvas

. . Hi there, everybody.
. . I have a canvas defined by many points (x,y)--it's not rectangular, but at least it will follow some almost-hexagonal shape (like a distorted hexagon, with angles that are always < 180 degrees). I also have a big collection of different rectangles (more or less 140 of them, with different widths and heights) and I need to position them inside the shape. They must be positioned as if they were being pushed by gravity (I mean... the top of the shape doesn't needs to be filled, but the bottom needs).
. . Right now my only idea is to store the min and max "x" position for every "y" position (something like: limits[300] = [30,30]; limits[299] = [29, 32]; ...), loop through the rectangles, get their area and then compare the values to find the best position. The biggest issued I have right now is that they need to be organized in a "organic" way, not like a table (I can't have rows and columns and position them inside cells. they need to be positioned as good as they can be, like fluidly, side by side, one above other...). I'm not sure how to manage the positioning.
. . I know some good examples of "auto-balanced" objects (a good one is the "Ball Pool" Chrome Experiment: http://mrdoob.com/projects/chromeexperiments/ball_pool/), but they use rectangular canvas and circular objects, which are much easier to compare the limits.
. . Right now my best idea is to check the objects for every possible x/y combination, from bottom to up, from left to right, checking if any area would overlap, but this would probably lock the whole computer for the calculations for minutes (the more itens on the screen, the more calculations would be needed).
. . The project is running on Flash, but any example, tip, algorithm, paper or pseudo-code will be of great help.
I think you can get all done using a physics simulation. It might sound complicated, but it's not as hard as it sounds. There are several physics APIs for actionscript 3. I've used the as3 port of Box2D and I'm pretty happy with the results.
The way I would go about it is:
define shapes for the walls ( the lines that make your polygonal shape )
define the boxes(rectangles)
create the physics bodies with the proper display objects information(linkage id , etc. )
add them to the physics world and simulate.
I don't know what your experience with actionscript 3 is, but have a look at the World Construction Kit. It should allow you to get on track fast.

Resources