simple CloudFactory.

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
random
Posts: 158
Joined: Wed Aug 11, 2010 6:01 am

simple CloudFactory.

Post by random »

Hello in case of i am realy fresh to c++ and Irrlicht, and dident find something thats easy and simple to make some gasCloud effect in my first try of a spacegame with Irrlicht i made a realy simple class with billboards to do that for me.

Header

Code: Select all

#ifndef CCLOUDFACTORY_H
#define CCLOUDFACTORY_H
#include <irrlicht.h>


using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

class CCloudFactory
{
    public:
        CCloudFactory(scene::ISceneNode* virtualZeroNode, scene::ISceneManager *mgr, core::vector3df posMinAbsolute, core::vector3df posMaxAbsolute, int maxCount, f32 minSize, f32 maxSize, char* imageName, int imageCount, char* imageExtension);
        virtual ~CCloudFactory();

        core::vector3df GetposMinAbsolute() { return posMinAbsolute; }
        void SetposMinAbsolute(core::vector3df val) { posMinAbsolute = val; }
        core::vector3df GetposMaxAbsolute() { return posMaxAbsolute; }
        void SetposMaxAbsolute(core::vector3df val) { posMaxAbsolute = val; }
        int GetmaxCount() { return maxCount; }
        void SetmaxCount(int val) { maxCount = val; }
        f32 GetminSize() { return minSize; }
        void SetminSize(f32 val) { minSize = val; }
        f32 GetmaxSize() { return maxSize; }
        void SetmaxSize(f32 val) { maxSize = val; }
        char* GetimageName() { return imageName; }
        void SetimageName(char* val) { imageName = val; }
        int GetimageCount() { return imageCount; }
        void SetimageCount(int val) { imageCount = val; }
        char*  GetimageExtension() { return imageExtension; }
        void SetimageExtension(char*  val) { imageExtension = val; }

    public:
    private:

        core::vector3df posMinAbsolute;
        core::vector3df posMaxAbsolute;
        int maxCount;
        f32 minSize;
        f32 maxSize;
        char* imageName;
        int imageCount;
        char* imageExtension;

};

#endif // CCLOUDFACTORY_H
CPP

Code: Select all

#include "../include/CCloudFactory.h"

CCloudFactory::CCloudFactory(scene::ISceneNode* virtualZeroNode, scene::ISceneManager *mgr, core::vector3df posMinAbsolute, core::vector3df posMaxAbsolute, int maxCount, f32 minSize, f32 maxSize, char* imageName, int imageCount, char* imageExtension)
{

    IVideoDriver* driver = mgr->getVideoDriver();

//Wir brauchen ein Array welches die Billboards aufnimmt
    scene::ISceneNode* billBoardStore[maxCount];

    int i;

    for(i=1; i < maxCount; i++)
    {

//Random für Grösse Definieren
        int iMinSize = static_cast<int>(minSize);
        int iMaxSize = static_cast<int>(maxSize);
        int randomSize = rand() % (iMaxSize - iMinSize);
        f32 randomFloat = minSize + (float) randomSize;

//Billboard erstellen
        billBoardStore[i] = mgr->addBillboardSceneNode(virtualZeroNode, core::dimension2d<f32>(randomFloat, randomFloat));

//Random für X-Position erstellen
        int xMin = static_cast<int>(posMinAbsolute.X);
        int xMax = static_cast<int>(posMaxAbsolute.X);
        int randomX = rand() % (xMax - xMin);
        f32 randomXFloat = posMinAbsolute.X + (float) randomX;

//Random für Y-Position erstellen
        int yMin = static_cast<int>(posMinAbsolute.Y);
        int yMax = static_cast<int>(posMaxAbsolute.Y);
        int randomY = rand() % (yMax - yMin);
        f32 randomYFloat = posMinAbsolute.Y + (float) randomY;

//Random für Z-Position erstellen
        int zMin = static_cast<int>(posMinAbsolute.Z);
        int zMax = static_cast<int>(posMaxAbsolute.Z);
        int randomZ = rand() % (zMax - zMin);
        f32 randomZFloat = posMinAbsolute.Z + (float) randomZ;

//Billboard Position erstellen
        billBoardStore[i]->setPosition(core::vector3df(randomXFloat, randomYFloat, randomZFloat));

//Die BillboardTextur generieren und zuweisen
        char mixedImageArray[100];
        sprintf(mixedImageArray, "%s%d%s", imageName, rand() % imageCount + 1, imageExtension);
        billBoardStore[i]->setMaterialTexture(0, driver->getTexture(mixedImageArray));

//Textureigenschaften einstellen
        billBoardStore[i]->setMaterialFlag(EMF_LIGHTING, false);
        billBoardStore[i]->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
        billBoardStore[i]->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
    }

}

CCloudFactory::~CCloudFactory()
{
    //dtor
}

in your main

Code: Select all

#include "include/CCloudFactory.h"
//! Some code
//!CloudFactory
CCloudFactory* cloudf = new CCloudFactory(smgr->getRootSceneNode( ), smgr, core::vector3df (200,200,200), core::vector3df (1000,1000,1000), 60, 100, 1000, "../../media/clouds/set", 8, ".png");
You will may need to change the Includepath and the Path for the Images

AND there is surely crap inside those lines of code bit it is a small basic class that might be help someone others new to here.

greetz
grumpymonkey
Posts: 222
Joined: Mon Jan 19, 2009 10:03 pm
Location: Miami, Florida
Contact:

Post by grumpymonkey »

no screens?
Image
Virion
Competition winner
Posts: 2149
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

does it move around or stay static?
My company: https://kloena.com
My profile: https://zhieng.com
My co-working space: https://deskspace.info
My game engine: https://kemena3d.com
random
Posts: 158
Joined: Wed Aug 11, 2010 6:01 am

Post by random »

it stay´s static but if you what just make different animatedTextures (you can do this easy with Corel Ulead PhotoImpact or your desired photo animating program).

remember it makes a gas cloud so it uses the overlay of several different images , different sizes ...

it is just a very very basic class to understand what it does and to work with it, you can extend it, its nothing you put somewhere and you are finished, also the images you must make by your own, for static images you may want to use universe 3d...

most times you need very much longer to use a good working all in one product just to find out hiow it works that extending and understanding a basic class...

if you want to extend it you may want to add
textureAnimator
flyInCircleAnimator
some lightning specials with random billboard using a Texture like the particle.bmp texture from media folder of irrlicht

the class like it stays above makes just some randem billboards,
in
different sizes in a predefined range
with
different positions in a predefinded area
and textures them with
different different images

yes it is a poor class, sorry
Post Reply