-
June 12th, 2009, 09:39 AM
#1
Making a DLL, How??
I have made this class
Code:
// --- CG_DoorHandling.h --------------------------
#ifndef CG_DOORHANDLING_H
#define CG_DOORHANDLING_H
// Includes
#include "CG_GameObject.h"
#include "CG_ParticleManager.h"
enum eDoorState {
DS_CLOSED,
DS_OPENED,
DS_OPENING,
DS_CLOSING
};
enum eDoorType {
DT_PIVOT,
DT_SLIDING
};
// CG name space & "CG" stands for "Computer Games" ;-)
namespace CG {
/**
*
*/
class Door: public CG::GameObject {
public:
Door();
void alignAll();
//
void update();
void update(eDoorState doorState, Ogre::Vector3 CharacterPosition);
void onImpact(eObjectType Object1, eObjectType Object2, NxActor* Actor1, NxActor* Actor2, NxVec3 ImpactPoint);
void onBulletHit(NxActor *ActorHit, NxReal Distance, NxVec3 ImpactPoint, NxVec3 FaceNormal, eBulletType BulletType);
inline void setDoorClosingTime(Ogre::Real Seconds) { mDoorClosingTime = 1000 * Seconds; }
inline void setDoorNode(Ogre::SceneNode *DoorNode) { mDoorNode = DoorNode; }
inline void setDoorActor(NxActor *DoorActor) { mDoorActor = DoorActor; mDoorActor->raiseBodyFlag( NX_BF_KINEMATIC ); }
inline void setDoorTriger(NxActor *DoorTriger) { mDoorTriger = DoorTriger; }
inline void setDoorType(eDoorType DoorType) { mDoorType = DoorType; }
inline void setDoorOpeningSound(FMOD::Sound *OpeningSound) { mDoorOpeningSound = OpeningSound; }
inline void setDoorClosingSound(FMOD::Sound *ClosingSound) { mDoorClosingSound = ClosingSound; }
inline void setDoorBulletSound(FMOD::Sound *BulletSound) { mDoorBulletHitSound = BulletSound; }
ParticleManager *mDoorParticle;
private:
/**
*
*/
bool closeDoor();
/**
*
*/
bool openDoor();
//
Ogre::SceneNode *mDoorNode;
//
Ogre::Vector3 mDoorClosePosition;
//
NxActor *mDoorActor;
//
NxActor *mDoorTriger;
//
eDoorState mCurrentDoorState;
//
eDoorType mDoorType;
//
FMOD::Sound *mDoorOpeningSound;
//
FMOD::Sound *mDoorClosingSound;
//
FMOD::Sound *mDoorBulletHitSound;
//
FMOD::Channel *mSoundChannel;
//
Ogre::Timer *mDoorTimer;
//
Ogre::Real mDoorClosingTime;
};
}
#endif
// --- CG_DoorHandling.h --------------------------
and implementation in cpp
Code:
// --- CG_DoorHandling.cpp --------------------------
// Include header definition
#include "CG_DoorHandling.h"
namespace CG {
// =====================================================================
Door::Door() {
mObjectType = OT_DOOR;
mCurrentDoorState = DS_CLOSED;
mDoorClosingTime = 1000 * 3.0;
mDoorTimer = new Ogre::Timer();
mDoorParticle = new ParticleManager();
}
// =====================================================================
void Door::onImpact(eObjectType Object1, eObjectType Object2, NxActor *Actor1, NxActor *Actor2, NxVec3 ImpactPoint) {
}
// =====================================================================
void Door::onBulletHit(NxActor *ActorHit, NxReal Distance, NxVec3 ImpactPoint, NxVec3 FaceNormal, eBulletType BulletType) {
FMOD::System *mSoundSys;
FMOD::Channel *mChannel;
mDoorBulletHitSound->getSystemObject(&mSoundSys);
mSoundSys->playSound(FMOD_CHANNEL_FREE, mDoorBulletHitSound, true, &mChannel);
mChannel->set3DAttributes(Conversion::Vec3NxToFMOD(ImpactPoint), 0);
mChannel->setPaused(false);
// emit particle
mDoorParticle->emitParticles(Conversion::Vec3NxToOgre(ImpactPoint), Conversion::Vec3NxToOgre(FaceNormal));
}
// =====================================================================
void Door::update(eDoorState doorState, Ogre::Vector3 CharacterPosition) {
mCurrentDoorState = doorState;
FMOD::System *mSoundSys;
mDoorOpeningSound->getSystemObject(&mSoundSys);
mSoundChannel->stop(); // stop the sound if playing
if(mCurrentDoorState == DS_OPENING) {
mDoorActor->clearBodyFlag( NX_BF_KINEMATIC );
// play door opening sound
mSoundSys->playSound(FMOD_CHANNEL_FREE, mDoorOpeningSound, false, &mSoundChannel);
// add force to door for opening it
Ogre::Vector3 Direction = mDoorNode->getPosition() - CharacterPosition;
Direction.normalise();
NxVec3 Dir = Conversion::Vec3OgreToNx(Direction);
Dir *= 313;
mDoorActor->addForce(Dir);
mDoorTimer->reset();
}
else if(mCurrentDoorState == DS_CLOSING) {
mSoundSys->playSound(FMOD_CHANNEL_FREE, mDoorClosingSound, false, &mSoundChannel);
}
mSoundChannel->set3DAttributes(Conversion::Vec3NxToFMOD(mDoorActor->getGlobalPosition()), 0);
mSoundChannel->setPaused(false);
}
// =====================================================================
// =====================================================================
// =====================================================================
bool Door::closeDoor() {
if(mDoorClosePosition.positionEquals(mDoorNode->getPosition(), 0.7)) {
return (true);
}
else
{
Ogre::Vector3 Direction = mDoorClosePosition - mDoorNode->getPosition();
Direction.normalise();
NxVec3 Dir = Conversion::Vec3OgreToNx(Direction);
Dir *= 10;
mDoorActor->addForce(Dir);//, NX_IMPULSE);
return (false);
}
}
// =====================================================================
bool Door::openDoor() {
Ogre::Vector3 Direction = mDoorNode->getPosition() - mDoorClosePosition;
Direction.normalise();
NxVec3 Dir = Conversion::Vec3OgreToNx(Direction);
Dir *= 100;
mDoorActor->addForce(Dir);
return (true);
}
// =====================================================================
// =====================================================================
void Door::alignAll() {
//mDoorActor->setGlobalPosition( CG::Conversion::Vec3OgreToNx( mDoorNode->getPosition() ));
//mDoorActor->setGlobalOrientationQuat( CG::Conversion::QuaOgreToNx( mDoorNode->getOrientation() ));
mDoorNode->setPosition( Conversion::Vec3NxToOgre( mDoorActor->getGlobalPosition()));
mDoorNode->setOrientation( Conversion::QuaNxToOgre( mDoorActor->getGlobalOrientationQuat()));
mDoorClosePosition = mDoorNode->getPosition();
}
// =====================================================================
void Door::update() {
// update particle system
mDoorParticle->_updateParticleSystem();
// if the door is not close and timer has incresed for 2 second
if(mCurrentDoorState != DS_CLOSED && (mDoorTimer->getMilliseconds() > mDoorClosingTime) )
{
mCurrentDoorState = DS_CLOSING;
mDoorActor->clearBodyFlag( NX_BF_KINEMATIC );
mSoundChannel->stop(); // stop the sound if playing
// play a closing sound
FMOD::System *mSoundSys;
mDoorClosingSound->getSystemObject(&mSoundSys);
mSoundSys->playSound(FMOD_CHANNEL_FREE, mDoorClosingSound, false, &mSoundChannel);
mSoundChannel->set3DAttributes(Conversion::Vec3NxToFMOD(mDoorActor->getGlobalPosition()), 0);
mSoundChannel->setPaused(false);
}
// check where the door is opening or closing
if(mCurrentDoorState == DS_OPENING)
{
openDoor(); // add a little bit force to open the door
if(mDoorTimer->getMilliseconds() > 1000) { // if specific time has been elapsed means door has opend
mCurrentDoorState = DS_OPENED;
mDoorActor->raiseBodyFlag( NX_BF_KINEMATIC );
}
}
else if(mCurrentDoorState == DS_CLOSING)
{
if(closeDoor() == true) {
mCurrentDoorState = DS_CLOSED;
mDoorActor->raiseBodyFlag( NX_BF_KINEMATIC );
Ogre::LogManager::getSingleton().logMessage("******************************Door has been closed");
}
}
// update the door graphicla model
mDoorNode->setPosition(Conversion::Vec3NxToOgre(mDoorActor->getGlobalPosition()));
mDoorNode->setOrientation(Conversion::QuaNxToOgre(mDoorActor->getGlobalOrientationQuat()));
}
// =====================================================================
// =====================================================================
}
// --- CG_DoorHandling.cpp --------------------------
What i want to do,
I want to export this class into a dll,
so other cannot view the implimentation.
I only want to provide them header file only and that dll file so they will not be able to edit this class.
Thanks.
Muhammad Ahmed.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|