Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Aluthreney

Member Since 28 Jul 2011
Offline Last Active May 02 2013 03:50 AM
-----

Posts I've Made

In Topic: Scaling collision objects

02 April 2013 - 09:51 AM

 /// Adding terrain mesh to scene.
ITexture *texture=driver->getTexture("./assets/map_image_resize.jpg");
ITerrainSceneNode *terrain=smgr->addTerrainSceneNode(texture->getName(), 0 , -1, vector3df(0.0f, 0.0f, 0.0f), vector3df(0.0f, 0.0f, 0.0f), vector3df(1.0f, 1.0f, 1.0f));
    
terrain->setMaterialFlag(EMF_LIGHTING, false);
terrain->setMaterialTexture(0, driver->getTexture("./assets/map_texture.jpg"));
terrain->setPosition(vector3df(0.0f, 0.0f, 0.0f));
terrain->setScale(vector3df(4.0f, 1.0f, 4.0f));

 /// Messing around with btHeightfieldTerrainShape.
vector3df scale=terrain->getScale();
aabbox3d<f32> box=terrain->getBoundingBox();
const vector3df size=box.getExtent()/scale;
f32 minHeight=((ITerrainSceneNode*)terrain)->getHeight(0, 0);
f32 maxHeight=minHeight;

int arraySize=texture->getSize().Height;
f32 heightData[ize*arraySize];
const f32 stepWidthX=size.X/arraySize;
const f32 stepWidthZ=size.Z/arraySize;
u32 runVal=0;

vector3df minEdge=box.MinEdge/scale;
vector3df maxEdge=box.MaxEdge/scale;

 //This cycle gives me the min and max height as well as the height value of each point of my terrain.
for(f32 z=minEdge.Z; z<maxEdge.Z; z+=stepWidthZ)
{
    for(f32 x=minEdge.X; x<maxEdge.X; x+=stepWidthX)
    {
        const f32 curVal=((ITerrainSceneNode*)terrain)->getHeight(x, z);

        heightData[runVal++]=curVal;

        if(curVal>maxHeight){maxHeight=curVal;}
        if(curVal<minHeight){minHeight=curVal;}
    }
}

f32 *heightDataPtr=heightData;

 /// Working with Bullet.
  // Collision Objects.
btCollisionShape *groundShape=new btHeightfieldTerrainShape(arraySize, arraySize, heightDataPtr, 1.f, minHeight, maxHeight, 1, PHY_FLOAT, false);
groundShape->setLocalScaling(btVector3(4.0f, 1.0f, 4.0f));
btCollisionShape *sphereShape= new btSphereShape(10);

  // Ground Motion State.
btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3(0.0f, 0.0f, 0.0f));
btDefaultMotionState *groundMotionState=new btDefaultMotionState(transform);

  // Ground Rigid Body.
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
btRigidBody *groundRigidBody=new btRigidBody(groundRigidBodyCI);
groundRigidBody->setUserPointer((void *)terrain);

  // Adding ground rigid body to the world.
m_dynamicsWorld->addRigidBody(groundRigidBody);

  // Sphere Motion State.
btDefaultMotionState *sphereMotionState=new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(100, 400, 100)));

  // Adding mass to the sphere object.
btScalar mass=1;
btVector3 sphereInertia(0, 0, 0);
sphereShape->calculateLocalInertia(mass, sphereInertia);

  // Sphere RigidBody.
btRigidBody::btRigidBodyConstructionInfo sphereRigidBodyCI(mass, sphereMotionState, sphereShape, sphereInertia);
btRigidBody *sphereRigidBody= new btRigidBody(sphereRigidBodyCI);

  // Creating irrlicht sphere.
ISceneNode *irrSphere=smgr->addSphereSceneNode(10);
irrSphere->setMaterialFlag(EMF_LIGHTING, false);
irrSphere->setMaterialTexture(0, driver->getTexture("./assets/ice_texture.jpg"));

sphereRigidBody->setUserPointer((void *)irrSphere);

  // Adding sphere rigid body to the world.
m_dynamicsWorld->addRigidBody(sphereRigidBody);

In Topic: How to make a facebook card game? (REALLY amateur)

07 March 2013 - 04:04 AM

I don't know much about card games, but, if it were me, I would start doing some googling on how non-digital card games are designed and developed. After that I would create an exaustive rough draft / design document of the card game before finaly making it into a video game.

 

As for putting the game on facebook: I would worry about actually getting the game done before thinking of something like that, but again, if it were me, I would contact facebook (after having, at least, a prototype of the game) and ask them if they would be interested in adding the game to their website.

 

In my opinion, I don't think putting your game on facebook is a very wise decision. From what I've seen, facebook has lost a lot of it's hold in the gaming field in the last couple of years. A better idea would be to make it into an app for android or some other mobile device. I'm saying all of this with the idea that you want to make some money with this game, but if your only goal is to make a fun game then go for it biggrin.png


In Topic: Deleting value stored inside a pointer

27 January 2013 - 05:39 AM

Ok I got it working thank you everyone for your advice, it really helped. Just one last question though: Even though the instance of the Monster disappears on screen (3d object is not rendered), is there a way to make sure the memory that was holding the instance is properly "cleaned"?


In Topic: Deleting value stored inside a pointer

26 January 2013 - 08:09 PM




Deleting something doesn't automatically set the pointer to null. You'll need to nullify it yourself.

delete ptr[x];ptr[x] = NULL;
But if you take this approach, then you need to check for NULL every time you access the array.
If you need to litter your code with null-checks, then you have ownership issues that needs to be solved instead. You should not ask yourself if you need to check for null before accessing a pointer, you should ask yourself why the pointer can be deleted in the first place if you still need it.

If you delete the objects you have allocated, but then keep using the objects afterwards, your program is ill-formed. That does not mean that your program must crash or must produce an incorrect result. It may do that, but it doesn't have to. Nevertheless, your program is ill-formed.

I never said I was going to keep using the objects after I delete them. I said I was going to use the pointers and I don't want to delete the pointers, I want to delete what the pointers are pointing to.

Deleting something doesn't automatically set the pointer to null. You'll need to nullify it yourself.

delete ptr[x];ptr[x] = NULL;
But if you take this approach, then you need to check for NULL every time you access the array.
I was already planning for this though.
----------
Let me try and explain my idea.

I have two classes: class Monster and class Spawner.
The Monster class will have basic functions for movement, animations and keeping track of it's health, but it's the Spawner class that will control the creation and destruction of the Monster class instances.

So in the Spawner class I decided to create a pointer array of Monster class and also created two functions: createMonster() and killMonster().


//! definition of the createMonster() function...//! keep in mind that the pointer array has already been given the NULL value.
void createMonster()
{    
    while(int x; x<=9; x++)    
    {        
        if(ptr[x]==NULL)        
        {            
            ptr[x]= new Monster;        
        }    
    }
}


//! definition of the createMonster() function...
void killMonster(int x) //! the parameter is the particular pointer in the array that I want to clear.
{    
    code...code...code...    
    //! The line of code that will destroy the instance of the Monster class so that I can make the pointer NULL, in order to be re-    
    //! utilized at a later date to hold a new instance of the Monster class, goes here.    
    ptr[x]=NULL;
}
The code might look a bit empty, but I stripped it down to the bare bones in order to clarify the idea I'm trying to convey.

In Topic: Deleting value stored inside a pointer

26 January 2013 - 07:07 PM

You need to call delete for everything you call new for. You call new for ptr[x], for each x in the array, so you need to call delete for ptr[x] as well.

for(int x=0; x<10; ++x) {
    delete ptr[x];
}

I tried doing this, but it didn't do anything. The class instance contains a 3d object that is rendered when I run the program. Supposedly, when I delete the contents inside the  pointer (using delete ptr[x]) the image wont render when I run the program, but it does...

 

delete ptr[5];

You can't (shouldn't) delete ptr because it wasn't newed:

myClass** arr = new myClass*[10];
for ( auto& obj : arr )
    obj = new myClass();

// ...

for ( auto& obj : arr )
    delete obj;
delete[] arr;

I don't want to delete the pointer only what it's pointing to.


PARTNERS