Archive

Archive for the ‘C++’ Category

GTBot Source

Written on March 13th 2008, 16:03 by sYnie

A lot of people asked for the source code of GTBot. It’s a C++-based bot for GTChat, which I wrote some years ago. You can download it under the terms of GPL:

Beware! The source code is years old. It’s from times when I started to learn C++. So it’s really messed up and absolutely not nice. Better use it as a compilation of some functions for the GTChat, than using the bot in productive use. Everyone is welcome to go through the code, give it a nice OOP structure and send it back to me.

Mr Burns

Written on July 11th 2007, 03:07 by sYnie

I was searching for a tool to burn CDs and DVDs on Mac OS X without any GUI or interface. I’m used to the shell, as I’m a Linux user. The only option was to use hdiutil, whose commands I found too hard to remember. So I coded a small program, which makes use of hdiutil in order to easily burn DVDs and CDs using the terminal. The name of it is “Mr Burns” ;-)

Download:

After copying the applications to a path within your $PATH variable, it can be used like this:

  • `mrburns` for copying disc2disc (with the first 2 drives found)
  • `mrburns -o devicenumber` defines the drive you want to burn with
  • `mrburns -i file|folder|image|devicenumber` defines the file or image or device you want to burn.
  • `mrburns -l` lists all the devicenumbers (for usage with -o or -i)
  • `mrburns –help` to read what i just wrote

Examples:

  • `mrburns -i 2` uses device number two to read from
  • `mrburns -i /Users/synie/a_folder -o 1` burns the content of this folder to the disc in device 1
  • `mrburns -i ~/foo.iso` burns this iso to the default burning device

A lot of mac users aren’t used to the shell in a way, that they would even use it to burn discs. But maybe this app is helpful for some Linux guys who sometimes work with macs ;-)

Code Snippet: OGRE

Written on November 20th 2006, 12:11 by sYnie

Some days ago I started to work with ogre. In order to display 2D elements, I have used a nice class written by Hernán Moraldo (Nov 06).

I wrote a small class in order to set pictures using pixel coordinates. I’ve also implementet things like animations, etc.

image.h:

#ifndef image_h
#define image_h

#include “2d.h”
#include <iostream>
#include <ogre .h>
#include <ogretimer .h>
using namespace Ogre;
using namespace std;

class OImage : public Ogre2dManager
{
public:
OImage(Root *r, std::string cF);
~OImage();
void addImage(std::string cF);
void draw();
void setXYByPx(int x, int y);
void setWHByPx(int w, int h);
void moveX(float px);
void moveY(float py);
void setX(float px);
void setY(float py);
float getX();
float getY();
float getW();
float getH();
void setVisible(bool vis);
bool getVisible();
void setAnimated(bool anim);
bool getAnimated();
void setAnimationspeed(int time);
int getAnimationspeed();

protected:
Root *r;
SceneManager *sm;  // Scenemanager device
std::string images[24];  // the image array
int curImage;  // Which image shall be displayed ?
float x;  // x from 0 to 1
float y;  // y from 0 to 1
float w;  // w from 0 to 1
float h;  // h from 0 to 1
float pxw;  // W in pixels
float pxh;  // H in pixels
bool visible;
bool animated;
int animSpeed;
unsigned long lastTime;
Timer* timer;

};

#endif

image.cpp:

#include “image.h”

OImage::OImage(Root *rp, std::string cF) : Ogre2dManager()
{
timer = new Timer();
visible = 1;
animated = 0;
lastTime = timer->getMilliseconds();
x = 0.5;
y = 0.5;
w = 0.5;
h = 0.5;
r = rp;
sm = r->getSceneManager(”sceneManager”);
images[0] = cF;
curImage = 0;
animSpeed = 30;
init(sm, Ogre::RENDER_QUEUE_OVERLAY, true);
TextureManager::getSingleton().load(images[curImage], “General”);
}

OImage::~OImage()
{
end();
}

void OImage::addImage(std::string cF)
{
for (int i = 0; i < = 31; i++)
{
if (images[i] == “”)
{
images[i] = cF;
TextureManager::getSingleton().load(images[i], “General”);
break;
}
}
}

void OImage::draw()
{
if (animated)
{
if ((timer->getMilliseconds()-lastTime) >= animSpeed)
{
curImage++;
if (curImage >= 32)
curImage = 0;
if (images[curImage] == “”)
curImage = 0;
lastTime = timer->getMilliseconds();
}
}

if (visible)
spriteBltFull(images[curImage], (x*2)-1, ((y*2)-1)*(-1), ((x*2)-1)+(w*2), ((y*2)-1)*(-1)-(h*2));
}

void OImage::setXYByPx(int px, int py)
{
x = ((1.0/r->getAutoCreatedWindow()->getWidth())*px);
y = ((1.0/r->getAutoCreatedWindow()->getHeight())*py);
setWHByPx(pxw, pxh);
}

void OImage::setWHByPx(int pw, int ph)
{
pxw = pw;
pxh = ph;
w = ((1.0/r->getAutoCreatedWindow()->getWidth())*pw);
h = ((1.0/r->getAutoCreatedWindow()->getHeight())*ph);
}

//
// to move the image between -1 and 1
//
void OImage::moveX(float px)
{
x += px;
}

//
// to move the image between -1 and 1
//
void OImage::moveY(float py)
{
y -= py;
}

//
// to set the image
//
void OImage::setX(float px)
{
x = px;
}

//
// to set the image
//
void OImage::setY(float py)
{
y = py;
}

float OImage::getX()
{
return x;
}

float OImage::getY()
{
return y;
}

float OImage::getW()
{
return w;
}

float OImage::getH()
{
return h;
}

//
// sets wether the image is blitted or not
//
void OImage::setVisible(bool vis)
{
visible = vis;
}

//
// will the image be blitted ?
//
bool OImage::getVisible()
{
return visible;
}

//
// changes the images from the image array
//
void OImage::setAnimated(bool anim)
{
animated = anim;
}

//
// is it animated ?
//
bool OImage::getAnimated()
{
return animated;
}

//
// Changes the time (in MS) between the images (animation)
//
void OImage::setAnimationspeed(int time)
{
animSpeed = time;
}

//
// Get the animationsoeed
//
int OImage::getAnimationspeed()
{
return animSpeed;
}

This is a Example:

OImage* anim;
cursor = new OImage(r, “anim1.png”);
cursor->addImage(”anim2.png”);
cursor->addImage(”anim3.png”); …
cursor->setWHByPx(32,32);
// In die mitte des Fensters setzen. r = Root-Objekt.
cursor->setXYByPx(r->getAutoCreatedWindow()->getWidth()/2,r->getAutoCreatedWindow()->getHeight()/2);
// Animation:
cursor->setAnimated(1);
cursor->setAnimationspeed(15);

// In frameStarted():
cursor->draw();