Programming 2D Games

The official forum for "Programming 2D Games" the book by: Charles Kelly

It is currently Fri Feb 28, 2020 7:45 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Jan 17, 2014 7:03 am 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
Hi Prof Kelly,

I have a question regarding your console's location in the game engine.

As far as I know, when you define the vertices of some geometry, it is in respect to the objects local space e.g points in relation to an x-y graph.

When I look at the vertex definition of your console I see this:

vtx[0] at (5,5);
vtx[1] at (505,5);
vtx[2] at (505,405);
vtx[3] at (5,405);

To me, that would create the following shape (not to scale):

Image

Then when you draw the console it would put the middle of the axis above (0,0), into the middle of the scene (world view 0,0).

But somehow your program draws it using the top left of the console in relation to the top left of the screen. I can't see in the code how or where this is happening.

Secondly, I am trying to add some collision detection and response to a quad that I can move into another quad. I am starting with the circle collision as it seems easier although wont be very accurate for quads but that's okay. I am currently stuck making the quad's not pass through eachother. I thought your toOldPosition function would achieve this but my quads jsut pass right through eachother. I know the collision is working because if I make the quad do something else eg go back to the centre of the screen that works correctly.

The code is currently

Code:
   if (quad1.collidesWith(quad2, collisionVector))
   {
      quad1.toOldPosition();
   }


I may be misunderstanding the function of toOldPosition. Any help would be great. Thanks a lot.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 20, 2014 10:12 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 554
{From page 242}
FVF. Describes the vertex format. We use D3DFVF_VERTEX, which is defined in graphics.h as a combination of D3DFVF_XYZRHW | D3DFVF_DIFFUSE. The member D3DFVF_XYZRHW indicates that the vertex position has already been transformed. In other words, X,Y,Z are the screen coordinates of the vertices.

The oldX, oldY and oldAngle variables must be saved as part of the update function in order for the toOldPosition function to work as expected.

From Ship::update
Code:
    oldX = spriteData.x;                        // save current position
    oldY = spriteData.y;
    oldAngle = spriteData.angle;

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 21, 2014 8:06 am 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
Hi professor,

I made sure to update the old position as you instructed but the quad still passes through its friend. I have also checked with the debugger and the values are changing correctly as I move it.

Perhaps I have not fully understood the implementation of this function.

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 22, 2014 12:02 am 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 554
It may be the order in which you are updating the values.

The basic idea is to save the current location to the old variables then move. If a collision is detected each entity is moved back to its previous location.

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 22, 2014 11:18 am 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
Hi Professor,

Thanks, that was exactly the problem. I was updating the movement first then storing that value as toOldPosition, now it makes sense to calculate toOldPosition first and then update the co-ordinates.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group