Zombeesh overview 1 – Collision detection circle based

After less than one week – weekend not counted in (I have had over 24hrs of sleep during weekend, I really hate to be sick) I have cought up with university material. Material covered:

  • Tile system for map loaded from a file
  • offset for moving map
  • entity manager for all objects on the map – plus improvement
  • messaging system – communication between instances of objects
  • collision detection – and my own improvement
  • moving around the map – mouse based
  • font manager

Plans for next week

  • Selecting objects by mouse click – hoping to select more than one element
  • collision detection applied for object on a map
  • placing building on the map
  • shooting to zombies and other stuff.

Meanwhile I will post some code – I haven’t done that for a while.

Collision detection class with improvements

// Collision.h
#pragma once
#ifndef COLLISION_H
#define COLLISION_H

const float TOUCH_DISTANCE = 0.000000000001;

static enum CollisionResults {
  NO_COLLISION, TOUCHING, OVERLAPPING
};

struct Circle{
  D3DXVECTOR3& position;
  float radius;
};

struct BoundingBox{
  D3DXVECTOR3& position;
  D3DXVECTOR3& size;
};

bool TestCollision(const BoundingBox& a, const BoundingBox& b);

CollisionResults TestCollisionCircle(const Circle& a, const Circle& b);
#endif

Pretty easy stuff here – two structs for BoundingBox and Circle enum for collision between circles – I have added it because I want to base selecting objects and – well all collision on two circles.

// Collision.cpp
#include "Collision.h"

bool TestCollision(const BoundingBox& a, const BoundingBox& b){
  float t;
  if((t = a.position.x - b.position.x) > b.size.x || -t > a.size.x)
    return false;
  if((t = a.position.y - b.position.y) > b.size.y || -t > a.size.y)
    return false;
  if((t = a.position.z - b.position.z) > b.size.z || -t > a.size.z)
    return false;
  return true;
}

CollisionResults TestCollisionCircle(const Circle& a, const Circle& b){
  //for math
  CollisionResults colliding;
  float distance_squared;
  float radii_squared;

  //a*a + b*b = c*c
  distance_squared = ((a.position.x - b.position.x)* (a.position.x - b.position.x))+
                     ((a.position.y - b.position.y)* (a.position.y - b.position.y));

  //Multiplication is faster than taking a square root
  radii_squared = (a.radius + b.radius) * (a.radius + b.radius);

  if( -TOUCH_DISTANCE < radii_squared - distance_squared &&radii_squared - distance_squared < TOUCH_DISTANCE) 		
    colliding = TOUCHING;
  else if(radii_squared > distance_squared)
    colliding = OVERLAPPING;
  else
    colliding = NO_COLLISION;

  return colliding;
}

pretty simple stuff here as well – Pythagorean theorem based. if distance between two points is bigger than sum of radius of circles then there is no collision if it is equal there is a collision but if it is smaller they overlap – so we have covered all 3 states first two for collision detection on the map and third one for selecting. simple

Backup plan

right,
I have spent too much time on trying to figure out 3D Picking and meshes.

I need to prepare backup plan – only 6weeks left till deadline.

here it is:

2D –  Top down – survival.

the idea is pretty the same as in 3D version – but I am considering get rid of building and as a production supplies – I mean we will have a farmers family that want to survive on their farm, yes sheep will be there.. here is scenario.

player controls 4 people team in where every unit has special skills – range, male dps, meal tank, healer – pretty standard rpg group.

I am considering as well game play ideally that would be multi player with server and clients but as far as now player will be able to control on of units and the rest will have some sort of AI. RPG elements will allow leveling for a team, and some perks will drop from zombies, wave time based play stays the same.

I have started developing engine from scratch.. again.. well this time I will base on university engine that we are developing at practicals by end of this week I should have:

  • Working framework
  • Tailed base map
  • Entity manager
  • Collision detection
  • Messaging system
  • Basic.. really basic AI
  • loads of small things like sprite renderer, game clock, animation engine, etc

Oh one big change.. I have decided to use DirectX9 instead on 10/11.. we are covering this one at university.. and I really do not have time to learn this one on my own.. probably later on I will do anyway.. but.. I am really tight with my time frames.

Day 11: Well I have done the textures

I cannot admit.. I wanted to finish couple more things..
well so now we have space to render divided to quads.. increase performance, texture, lighting, info about graphic card and memory left on card.

Now I am ready to do game logic.

what should I start with?
random placing objects on a map?
word!

I need to think of a build name for this project.. any suggestions?

Day 10: Height Map

I am satisfied with that height map – no multi textures, blending, water or even trees.. I need to concentrate on logic now, polishing details will be last thing.

plan for today/tomorrow.

picking + adding objects on the map..

good luck Luke..

thanks Luke.

edit:
ok 2 more thing left before I ll be ready to go with picking and objects,

1. need to set up camera in 45 degree
2. I need to think of optimisation.. some sort of quad tree or so..

Day 9: Motivation Kick

I need to figured out what I want/have to do with University and work.. need to find a balance,

Today after chat with my Program Leader I have decided to start going forward and developing stuff that I actually will need and polish small things at the end, that’s why today I have managed to create 1024 by 1024 grid map which will be base for my 3D hight map based strategy game, decisions has been made. nothing else left than developing..

Element Covered Tonight:

  • movement class
  • terrain class
  • grid helper

Tomorrow – Height map.

Day7: Quick overview

Just quick overview for end of day 7.

  • Input handler gets mouse position and escape button
  • Drawing 3D maya objects
  • Sound player
  • drawing 2D over 3d object
  • Font engine – well subsystem but..
  • High precision timing
  • FPS
  • CPU usage
  • Lighting

Still loads left to do but as for one week it is fairly enough!

Maya Converter Created v 0.1

I made this!

I have developed simple file that converts .obj file format exported from Maya to format that can be in easy way imported to my framework, processed and displayed! current version allows to import whole object with texture! This simple but really flexible script allows me to import any model exported to .Obj to the framework/engine.. how cool is that?!

some code below:

loading file and counts
[cc lang=”cpp”]
ifstream fin;
char input;

// counts.
vertexCount = 0;
textureCount = 0;
normalCount = 0;
faceCount = 0;

// open the file.
fin.open(filename);

// was successful in opening the file?
if(fin.fail() == true)
{
return false;
}

// beginning of the vertices section.
fin.get(input);
while(input != ‘v’)
{
// remainder of the line.
while(input != ‘\n’)
{
fin.get(input);
}

// start reading next line.
fin.get(input);
}

// vertices, texture coord, and normals counts
while(input == ‘v’)
{
fin.get(input);

if(input == ‘ ‘) { vertexCount++; }
if(input == ‘t’) { textureCount++; }
if(input == ‘n’) { normalCount++; }

// the line.
while(input != ‘\n’)
{
fin.get(input);
}

fin.get(input);
}

// number faces.
while(!fin.eof())
{
if(input == ‘f’) { faceCount++; }

// the line.
while(input != ‘\n’)
{
fin.get(input);
}

fin.get(input);
}

// Close the file.
fin.close();
[/cc]

now file processor:
[cc lang=”cpp”]
VertexType *vertices, *texcoords, *normals;
FaceType *faces;
ifstream fin;
int vertexIndex, texcoordIndex, normalIndex, faceIndex, vIndex, tIndex, nIndex;
char input, input2;
ofstream fout;

// Init the data structures.
vertices = new VertexType[vertexCount];
if(!vertices)
{
return false;
}

texcoords = new VertexType[textureCount];
if(!texcoords)
{
return false;
}

normals = new VertexType[normalCount];
if(!normals)
{
return false;
}

faces = new FaceType[faceCount];
if(!faces)
{
return false;
}

// the indexes.
vertexIndex = 0;
texcoordIndex = 0;
normalIndex = 0;
faceIndex = 0;

// open the file.
fin.open(filename);

// opened?
if(fin.fail() == true)
{
return false;
}

// parse of the vertices section.
fin.get(input);
while(input != ‘v’)
{
// the line.
while(input != ‘\n’)
{
fin.get(input);
}

// read the next line.
fin.get(input);
}

// Read vertices, texture coordinates, and normals into the data structures.
// + convert to left hand coordinate system.
while(input == ‘v’)
{
fin.get(input);

// read in the vertices.
if(input == ‘ ‘)
{
fin >> vertices[vertexIndex].x >> vertices[vertexIndex].y >> vertices[vertexIndex].z;

// Invert the Z vertex to left hand system.
vertices[vertexIndex].z = vertices[vertexIndex].z * -1.0f;

vertexIndex++;
}

// Read texture coords.
if(input == ‘t’)
{
fin >> texcoords[texcoordIndex].x >> texcoords[texcoordIndex].y;

// change the V texture coordinates to left hand system.
texcoords[texcoordIndex].y = 1.0f – texcoords[texcoordIndex].y;

texcoordIndex++;
}

// read normals.
if(input == ‘n’)
{
fin >> normals[normalIndex].x >> normals[normalIndex].y >> normals[normalIndex].z;

// normal to left hand system.
normals[normalIndex].z = normals[normalIndex].z * -1.0f;

normalIndex++;
}

// read line.
while(input != ‘\n’)
{
fin.get(input);
}

// next line.
fin.get(input);
}

//number of face indexes.
while(!fin.eof())
{
if(input == ‘f’)
{
// Read backwards – to a left hand system.
fin >> faces[faceIndex].vIndex3 >> input2 >> faces[faceIndex].tIndex3 >> input2 >> faces[faceIndex].nIndex3
>> faces[faceIndex].vIndex2 >> input2 >> faces[faceIndex].tIndex2 >> input2 >> faces[faceIndex].nIndex2
>> faces[faceIndex].vIndex1 >> input2 >> faces[faceIndex].tIndex1 >> input2 >> faces[faceIndex].nIndex1;
faceIndex++;
}

// the line.
while(input != ‘\n’)
{
fin.get(input);
}

// next line.
fin.get(input);
}

// close.
fin.close();

// output file.
fout.open(“model.txt”);

// header.
fout << "Vertex Count: " << (faceCount * 3) << endl; fout << endl; fout << "Data:" << endl; fout << endl; for(int i=0; i