• Create Account

# Ralara

Member Since 24 Sep 2010
Offline Last Active Apr 30 2014 06:15 AM

### In Topic: Rotating an object in a grid

18 February 2013 - 06:42 AM

I'm not 100% on Java so I may be wrong here, hopefully someone can correct me if I am, but although 'currentPiece' is public it is still inside the 'Tetris' class so the 'Piece' class cannot access it directly as you have, but it can access it through a 'Tetris' object. So it would be something like "Tetris.currentPiece", similar to the 'fall()' method where "Tetris.sleep(2000)" is used.

On a side note, there is a way of determining the rotation of Tetris pieces without having to store that location as you have in matrices (some people would argue that using tables is better as there is a limited number of shapes, but I prefer the algorithm personally).

• You define a block in the shape that will be the centre block that will be used to rotate around.
• Each other block is then defined in "shape space" relative to the centre, i.e. a block one column to the left will be [-1,0] relative to the centre block.
• When rotating (CW) the new row is the negative of the current column and the new column is the current row. So from the example above would become [0,1]. (This is still in "shape space", so is an offset from the centre block).
• For CCW rotation the negative is for the new column instead of the new row.

Below is a posting of my code performing the above (note this is in C++ not java);

```Vector2 Shape::BlockLocAfterRotate(UINT inBlockNum)
{
// Get the current location of the block
Vector2 outLoc = mBlocks[inBlockNum]->mLoc;

// Location of the centre block for this shape
Vector2 centreLoc = mBlocks[mID_CentreBlock]->mLoc;

// The offset of the current block from the centre of the shape
int offsetRow = centreLoc.y - outLoc.y;
int offsetCol = centreLoc.x - outLoc.x;

// The new location (in shape space)...
int newOffsetRow = -offsetCol; // New row is the negative of the previous col (still in shape space)
int newOffsetCol = offsetRow;  // New col is the previous row (still in shape space)

// Convert back to grid space
outLoc.x = centreLoc.x + newOffsetCol;
outLoc.y = centreLoc.y + newOffsetRow;

return outLoc;
}

```

Edit: Doing the algorithm way means you can just update the x,y components of your piece instead of having to create a new Piece every time and could very solve your problem too!

### In Topic: Second entity moves really slow!

06 February 2013 - 03:18 AM

I'm not 100% sure on how your timer works, but I would imagine the get_ticks() function returns how many ticks there have been since the last time it was called?

If so, then you should only call get_ticks() once per cycle (at the beginning of the main while loop in your case) and store this in a variable. Then use this value for both the player and the enemy.

As you are calling get_ticks() for each entity, there are less ticks happening between the call for the first entity and the second entity than there are between the second and the first, because of all the other stuff happening in between,

Let me know if this works or not!

### In Topic: XMMatrixOrthographicLH Question

15 January 2013 - 03:15 AM

Ah, turns out my Z was getting set to 0 and I hadn't noticed! I can't test my code right now but if I change it so the vertex Z is set to the near Z and use my original values, would I be correct in assuming it would work?

Thanks for your response though, makes a lot of sense. Always the simplest things that can be the hardest to spot when they are right in front of you  !!

### In Topic: Mesh loaded with Assimp not showing up

11 October 2012 - 02:02 AM

The transformation matrices are just to work out how one sub-mesh is relative to its parent mesh so its not essential and you should at least be seeing something on screen. I'm at work at the moment, but when I get home tonight I'll edit this post with the code I am using / a link of where to download it from.

 - The current version of the source code I am using can be found at http://www.adamsmith-demos.co.uk/wp-content/uploads/downloads/2012/10/Source.rar. This is only the code, if you want you can build it to debug it but its a directX11 project so you'll need the sdk and an 11 card.

If you want you can link to your code and we can both see if we can spot the problem?

### In Topic: Mesh loaded with Assimp not showing up

08 October 2012 - 12:38 PM

I was just about to explain why I thought you were only loading one because I could have sworn I'd seen when debugging that the aiScene only had a single mesh, but I just ran it again and it had 6... going mad I think!

PARTNERS