Frustum Culling – First Clash in OpenGL

Lately I have started preparing tools for voxel engine, after yesterdays fails with bloom/hdr today I won the battle with Frustum Culling – well it was only battle and there is still lot to improve.
Above we can see snowman’s – my tech model – used in OpenGL API learning process.

Anyway – for some weird reason I have decided that drown “testing models” will be in red. and the colling ones green – don’t ask. Fairly quickly I figured out that culling is updating only when camera is in the move. when rotates frustum is not being updated.. Need to investigate that.
Not tonight..

At the end of this week I can say game is almost finished!

Huzzah! Game as it should be is pretty much finished – well there is always something that can be added, improved or modified – but as far as I am considered Ā game should look like it looks atm.

Obviously, it needs final touches – tidying up GUI for instance.
and before handing it out I still need to improve zombies’ behavior, add some more animations, and most important implement behavior module into marines class.

but as I mentioned – I am pretty happy with what I have done.

Economic system is an interesting one.

We start with 500 coins, or whatever it is šŸ˜‰
then every 10 seconds we add x into the pull – where x is defined by 5*number of houses – number of marines. – I was thinking a bit about that and it seems to be a reasonable solution.
as well Limit system has been added – into economics manager class – to avoid negative values for income and other issues. our population limit is 5 times number of houses – note: scv is excluded. Yes, I know it is a bit weird but lets say SCV is not a human ;P

yes I know I haven’t done much this week but in my defense – I am sick and on Saturday I was in Dundee – Games in Scotland – pretty awesome event where teams such as Veemee, Codeplay or Digital Goldfish were presenting what are they doing and who they are looking for in terms of employment.
Some photos below:




We can buy stuff!

Finally I have prototyped pouching units system – it uses messaging system, however I am having weird bug, when I am getting more marines animation for them is speeding up. I am wondering if it is caused by using pointer to the animation.. well it shouldn’t, should it? to be fair animation system was designed for animating single instance of the object but still.. it should be flexible enough to handle that.

I haven’t tested that on buildings yet… – memo added šŸ™‚

the scenario is:
when single building is selected we can press “T” to train marines, atm. it is done instantly and target location for new “trained” unit is set to fixed location.

future improvements include:

  • developing training time
  • changeable spawn location
  • implement cost
  • as far as I am thinking about that game.. I need decent GUI!

there is loads to do.. argh.. damn you father time! why one day has only 24hrs?!

2D Zombieesh Continues

That was freaking remarkable week,

Meetings Meetings Meetings.

Apparently I have enough “clients” to open my own company. Yeah.. who could even thought about that? World is crazy.

anyway, this is not what post will be about.

What I want to show is today’s achievement. Zombeesh project šŸ™‚ – yes as you can see I have implemented sprites from Starcraft – still there is a lot to do – shadows, moving elements, etc but I need to create working prototype of a game in less than month.. and believe me it will be tough.. Group project, own company – planning, game development for xBox360 – yes on site We šŸ™‚ will be developing xBox game well I cannot tell much about it yet but nick name for a project is “Craft” – yeah I need work something better.. but that can wait. Back to the topic

  • I have managed to implement animations – but making them work is later issue.
  • GUI manager allows me to add text on a screen to any position – future development placing images and animations – can be shifted for later on.
  • SCV on a screen can buildĀ barracks in selected place, but to do that need to get there,
  • Small fix for approximationĀ error has been placed – SCV wasn’t moving to exact place, if it is close enough it/he (?) stops.

This weekend’s development plan – allow barracks to trainĀ Marines/Ghosts

Zombeesh back in 2D

After lately chat with my tutor I have to move back to 2D based game. – timeĀ pressureĀ and general overloading forced me to make thisĀ decision.
GDD must be finished by tomorrow – but shall not fear! I have some resources. I will borrow units tile set from star craft – come on zombies looks almost like infected marine

as well as terrain tiles – provided by Maniak – thanks man!

I am improving level manager so I will be able to deal with offsets and a stuff.. as far as now I have prototype and hopefully it will be ready in next couple hours.

// LevelManager.h

#pragma once

#ifndef LEVELMANAGER_H
#define LEVELMANAGER_H

[...]
#include "Level.h"

class LevelManager
{
private:
  //list of maps
  static std::map levels;
  static int currentLevelId;	
public:
  static LevelManager* instance;
  static void init();
  static void loadLevel(Level* level); // load level
  static void unloadLevel(Level* level); 
  static void registerLevel(Level* level); //add level to levels pool
  static Level* getLevel(int id) ;
  static D3DXVECTOR3 getOffset(); //gets offset off current map;

  LevelManager();
  ~LevelManager();
};
#endif
// LevelManager.cpp
#include "LevelManager.h"

int LevelManager::currentLevelId=-1; //no level
LevelManager* LevelManager::instance =0;
std::map LevelManager::levels = std::map();

LevelManager::LevelManager(){}

void LevelManager::init(){
  LevelManager::instance = new LevelManager();
}

LevelManager::~LevelManager(){
  if(!levels.empty()){
    std::map::iterator iter = levels.begin();
    for(; iter != levels.end(); ++iter){
      delete iter->second;
      iter->second = 0;
    }
    levels.clear();
  }
}

void LevelManager::loadLevel(Level* level){
  registerLevel(level);
  LevelManager::currentLevelId = levels.size();
}

void LevelManager::unloadLevel(Level* level){
  std::map::iterator iter = levels.find(level->getId());
  if(iter != levels.end())
    levels.erase(iter);
}

void LevelManager::registerLevel(Level* level){
  //get size of current levels list and increment by one
  int size = levels.size() + 1;
  levels[size]= level;
  level->setId(size);
}

//ok do I need to register all entitys into level? - I guess I do. need to double check that with Kevin
Level* LevelManager::getLevel(int id){
  std::map::iterator iter = levels.find(id);
  if(iter != levels.end()){
    return iter->second;
  }
  return 0;
}

D3DXVECTOR3 LevelManager::getOffset(){
  std::map::iterator iter = levels.find(currentLevelId);
  if(iter != levels.end())
    return iter->second->getOffset();
  return D3DXVECTOR3(0,0,0);
}

Frame Animation manager – 2D

This week at university we have covered 2D frame animation – simple idea every frame is separate image.

what we need are two classes:

  • Animation
  • AnimationManager
// Animation.h
#pragma once
#ifndef ANIMATION_H
#define ANIMATION_H

#include 

class Animation
{
private: 
  IDirect3DTexture9* texture;
  int frameWidth;
  int frameHeight;
  int startFrame;
  int endFrame;
  int frameCount;
  float frameTime;
  bool isLooping;
public:
  Animation(IDirect3DTexture9* texture);
  Animation(IDirect3DTexture9* texture, float frameTime, bool isLooping);
  Animation(IDirect3DTexture9* texture, float frameTime, bool isLooping, int startFrame, int endFrame,int frameWidth, int frameHeight);
  ~Animation();

  void setTexture(IDirect3DTexture9* newTexture){ texture = newTexture; }
  IDirect3DTexture9* getTexture(){ return texture;}

  void setFrameTime(float newFrameTime){ frameTime = newFrameTime;};
  float getFrameTime(){return frameTime;}

  void setIsLooping(bool newIsLooping){ isLooping = newIsLooping; }
  bool getIsLooping() { return isLooping; }

  void setStartFrame(int newStartFrame) { startFrame = newStartFrame;}
  int getStartFrame() { return startFrame;}

  void setEndFrame(int newEndFrame) { endFrame = newEndFrame; }
  int getEndFrame() { return endFrame; }

  void setFrameCount(int newFrameCount) { frameCount = newFrameCount; }
  int getFrameCount() { return frameCount;}

  void setFrameWidth(int newFrameWidht) { frameWidth = newFrameWidht; }
  int getFrameWidth() { return frameWidth; }

  void setFrameHeight(int newFrameHeight) { frameHeight = newFrameHeight; } 
  int getFrameHeight() { return frameHeight; }
};
#endif

as we can see just bunch of attributes and geters/seters

// Animation.cpp
#include "Animation.h"

Animation::Animation(IDirect3DTexture9* texture): texture(texture){
  frameTime = 1.0f/ 30.0f;
  isLooping = true;
  D3DSURFACE_DESC desc;
  texture->GetLevelDesc(0, &desc);
  startFrame = 0;
  endFrame = desc.Width / desc.Height;
  frameCount = endFrame - startFrame;
  frameWidth = desc.Height; 
  frameHeight = desc.Height;
}

Animation::Animation(IDirect3DTexture9* texture, float frameTime, bool isLooping)
: texture(texture), frameTime(frameTime),isLooping(isLooping){
  D3DSURFACE_DESC desc;
  texture->GetLevelDesc(0, &desc);
  startFrame = 0;
  endFrame = desc.Width / desc.Height;
  frameCount = endFrame - startFrame;
  frameWidth = desc.Height; 
  frameHeight = desc.Height;
}

Animation::Animation(IDirect3DTexture9* texture, float frameTime, bool isLooping, int startFrame, int endFrame,int frameWidth, int frameHeight)
: texture(texture),
frameTime(frameTime),
isLooping(isLooping),
startFrame(startFrame),
endFrame(endFrame),
frameWidth(frameWidth),
frameHeight(frameHeight) {
  frameCount = endFrame - startFrame;
}

Animation::~Animation(){}
// AnimationManager.h
#pragma once
#ifndef ANIMATIONPLAYER_H
#define ANIMATIONPLAYER_H

#include "Animation.h"
[...]
class AnimationPlayer
{
private:
  Animation* currentAnimation;
  std::string playing;
  std::map animations;
  int frameIndex;
  float time;
public:
  AnimationPlayer();
  void playAnimation(std::string name);
  void addAnimation(std::string name, Animation* anim);
  void update(float frameTime);
  void draw(ID3DXSprite* spriteBatch, D3DXVECTOR3 position, D3DXMATRIX transform);

  ~AnimationPlayer();
  Animation* getCurrentAnimation(){return currentAnimation;}

  std::string getPlaying(){ return playing; }
  int getFrameIndes() { return frameIndex;}
};
#endif

Animation manager keeps all animations in map, pointer to current animation, playing are easy to guess.

same with methods: playAnimation, addAnimation, draw and getCurrentAnimation but why there is an update method?
well code should make that clear.

// AnimationManager.cpp
#include "AnimationPlayer.h"

AnimationPlayer::AnimationPlayer(){}

AnimationPlayer::~AnimationPlayer(){
  std::map::iterator iter = animations.begin();
  for(; iter != animations.end(); ++iter){
    delete iter->second;
  }
  animations.clear();
}

void AnimationPlayer::playAnimation(std::string name){
  Animation* anim = animations[name];
  if(anim == currentAnimation)
    return;

  currentAnimation = anim;
  playing = name;
  frameIndex = 0;
  time = 0.0f;
}

void AnimationPlayer::update(float frameTime){
  if(currentAnimation == 0)
    return;

  time += frameTime;

  while(time > currentAnimation->getFrameTime()){
    time -=currentAnimation->getFrameTime();
    if(currentAnimation->getIsLooping())
      frameIndex = (++frameIndex) % currentAnimation->getFrameCount();
    else
      frameIndex = min(++frameIndex, currentAnimation->getFrameCount() - 1);
  }
}

void AnimationPlayer::draw(ID3DXSprite* sprite, D3DXVECTOR3 position, D3DXMATRIX transform){
  if(currentAnimation == 0)
    return;
  D3DXMATRIX currentTransform;
  sprite->GetTransform(¤tTransform);
  sprite->SetTransform(&transform);

  int frameX = (frameIndex + currentAnimation->getStartFrame());
  frameX *= currentAnimation->getFrameWidth();

  int frameY = (frameIndex + currentAnimation->getStartFrame());
  frameY *= currentAnimation->getFrameWidth();
  frameY %= currentAnimation->getFrameWidth();

  RECT rect;
  rect.left = frameX;
  rect.right = frameX + currentAnimation->getFrameWidth();
  rect.top = frameY;
  rect.bottom = frameY + currentAnimation->getFrameHeight();

  sprite->Draw(currentAnimation->getTexture(), &rect, 0, &position, D3DCOLOR_XRGB(255,255,255));
  sprite->SetTransform(¤tTransform);
}

I am bit worried because all stuff we do leads us – students to develop 2D based platformer game.. next week we are going to do simple 2d physics and particles.. which is not really necessary in my game.

but good news is.. I have managed to get back on track with my 3D Zombeesh.. some tech demo should be ready by end of the week!! can’t wait!