firing a projectile

psychosmurf

08-09-2006 02:36:12

hey guys .. i am playing around with nxogre and i am still pretty new to it. I am trying to fire a projectile but it doesn't seem to be working. I have been trying to use the code provided in the 116 tutorial but what seems to be happening is you see the object for like 1 frame and then is disappears. Now i didn't make a seperate projectile class i just made a shootball method in the playerstate class like so..

void PlayerState::shootBall(Ogre::Vector3 playerPos, Ogre::Quaternion playerQuat, nxOgre::scene *scen, Ogre::SceneManager *sm, Ogre::SceneNode *sn)
{

Ogre::Vector3 pPos = playerPos;
Ogre::Quaternion quat = playerQuat;

dir = quat * Vector3::UNIT_Z; //calculate the direction
pPos.y += 10;
Vector3 newpos = pPos + dir;


mProjs = scen->createBody("bullet" + Ogre::StringConverter::toString(count++), "barrel.mesh",new sphereShape(10),10,pPos);
//mProjs->setAutoDeletable(false);
mProjs->mNode->scale(Vector3(0.5,0.5,0.5));

mProjs->setGlobalPosition(playerPos.x + 20, playerPos.y+50, playerPos.z);

mProjs->addLocalForce(dir * newpos);

myNamespace::writeF("POS.log","zomfg it is hitting it");
}


now i am using bits of code from 116 and another projectile example i got off the forums here. I have it writing to a file when ever the code is executed. Like i stated above it is there for like 1 frame and then it dissapears. in my gamestate i just have:

if(e->getKey() == KC_P)
{
nxOgre::scene* mScene = mWorld->getScene("Main");
rayne->shootBall(vec, rayne->getSceneNode()->getOrientation(), mScene, mSceneMgr, bulletNode);
}


i am passing in the player location and the scene and the scene manager and the for what ever reason that bulletnode lol ... i don';t think i even use it in the other code .. just noticed now.

anyone got any ideas? any suggestions would be great =p thx.

psychosmurf

M@gg!

08-09-2006 05:23:26

At the moment I can't find the reason. Maybe the force is to hight, so that it is gone in an instant.

When you add localForce, you should set:
mBdyBody->setGlobalOrientation(mDirection)

Where mDirection is the direction you wana shoot the projectile.

betajaen

08-09-2006 09:13:30

Agreed, I believe the force is to high for the density/shape.

Try this though in your frameListener:


myNamespace::writeF("POS.log","ROFLS it is @" + Ogre::StringConverter::toString(mProjs->getGlobalPosition()));


If it helps at all, I've written "setVelocity" and working on CCD (continous collision detection) in the next point release which will be ooohh a week or two ;)

psychosmurf

08-09-2006 14:56:11

when ever I stry to write a vector to that file i get this error: c:\school\GGVV_Programming\UrbanCityLevel.cpp(322): error C2664: 'myNamespace::writeF' : cannot convert parameter 2 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]

blah i don't know why. I have another function to write vectors or a file and it crashes me out to.

humm i tried to lower the velocity but it doesn't seem to be doing anything .. maybe i am just doing it wrong lol i am going to keep trying arg. And i am looking forward to the new release =p hehe

betajaen

08-09-2006 15:40:12

Will stringName.c_str() work?

psychosmurf

11-09-2006 13:26:40

like:
myNamespace::writeF("POS.log","ROFLS it is @" + stringName.c(rayne->mProjs->getGlobalPosition());

???

lol sorry haven't slept much this weekend arg ...

betajaen

11-09-2006 14:42:10

no more like:


string s = Ogre::StringConverter::toString( rayne->...) ;
myNamespace ... ( ... " @ " + s.c_str());

psychosmurf

12-09-2006 13:51:05

hehe alright i tired what you said to but i am getting a new error now lol

code:

string s = Ogre::StringConverter::toString( rayne->mProjs->getGlobalOrientation());
myNamespace::writeF("POS.log","ROFLS it is @ " + s.c_str());

error:

c:\school\GGVV_Programming\UrbanCityLevel.cpp(751): error C2110: '+' : cannot add two pointers

thx for the help on this btw everyone =)

psychosmurf

betajaen

12-09-2006 14:55:13


myNamespace::writeF("POS.log",s.c_str());

psychosmurf

12-09-2006 15:46:41

i used:

myNamespace::writeF("POS.log",s.c_str());

and got:

c:\school\GGVV_Programming\UrbanCityLevel.cpp(751): error C2664: 'myNamespace::writeF' : cannot convert parameter 2 from 'const char *' to 'char *'


:(

betajaen

12-09-2006 16:19:22

Oh dear. What exactly is writeF?

psychosmurf

12-09-2006 16:48:09

this is the writeF function in the myNamespace class

static int writeF(char* fname, char* message)
{
ofstream outClientFile(fname, ios::app);

if(!outClientFile)
{
exit(1);
}

outClientFile << message << endl;

return 0;
}


there is also this function for vectors but it crashes my program aswell

static int writeV(char* fname, Ogre::Vector3 position)
{
ofstream outClientFile(fname, ios::app);

if(!outClientFile)
{
exit(1);
}

outClientFile << position << endl;

return 0;
}

betajaen

12-09-2006 17:14:52

Try this:
static int writeString(char* fname, std::string message)
{
ofstream outClientFile(fname, ios::app);

if(!outClientFile) {
exit(1);
}

outClientFile << message << endl;

return 0;
}


string s = Ogre::StringConverter::toString( rayne->mProjs->getGlobalOrientation());
myNamespace::writeF("POS.log","ROFLS it is @ " + s);

psychosmurf

12-09-2006 17:29:39

i take it you ment to use the writeString not writeF hehe ... but it is compiling but crashing in game now .. when i debug it seems to be pointing to the call to writeString arg lol

BlasterN

12-09-2006 21:23:46

i used:

myNamespace::writeF("POS.log",s.c_str());

and got:

c:\school\GGVV_Programming\UrbanCityLevel.cpp(751): error C2664: 'myNamespace::writeF' : cannot convert parameter 2 from 'const char *' to 'char *'


:(


need to cast !
myNamespace::writeF("POS.log",(char*)s.c_str());

mnm23

17-09-2006 05:20:10

Hey guys, psychosmurf is a part of my programming team. I have taken his projectile code and added it to my solution. I am able to print off vectors and quaternians. This is the current code.


Ogre::Vector3 pPos = playerPos - Vector3(0, 20, 0);
Ogre::Quaternion quat = playerQuat;

myNamespace::writeV("pPos position.log", pPos);
myNamespace::writeQ("quat position.log", quat);

Vector3 dir = quat * Vector3(0, 0, -100);

myNamespace::writeV("dir position.log", dir);

mProjs = scen->createBody("bullet" + Ogre::StringConverter::toString(count++), "cube.1m.mesh",new cubeShape(100),50,Vector3(pPos.x, -750.742, pPos.z + 50));

mProjs->addLocalForce(pPos * Vector3(0, 0, -100));


Whats going on here is im trying to set the position of the projectile just in front of the player. What is actually happneing in the game is the projectile is about 200 units above me (for whatever reason) and its only moving in the y-axis when i shoot it off. As you can see i have more things in here then i am currently using but thats because i was trying many different things in the addLocalForce and so far nothing works.

This is players postion when firing.

Vector3(6240, -810.742, -2966)

This is player orientation.

Quaternion(1, 0, 0, 0)

This is bullet positions.

Vector3(6240, -750.742, -2916)
Vector3(6240, 11.8319, -2916)
Vector3(6240, 70.9649, -2916)
Vector3(6240, 115.975, -2916)
Vector3(6240, 160.962, -2916)
Vector3(6240, 205.925, -2916)
Vector3(6240, 265.837, -2916)
Vector3(6240, 310.743, -2916)
Vector3(6240, 355.624, -2916)
Vector3(6240, 400.48, -2916)
Vector3(6240, 460.251, -2916)
Vector3(6240, 505.05, -2916)


Thanks again guys.

psychosmurf

20-09-2006 03:41:50

hehe well with mnm's help we got it working now .. but i am wondering how to acctually fire it off i have tried some things and i just seems to be droping it down to the right side of the camera ... now i am i am passing in the camera quaternion to the shoot function like so

Ogre::Quaternion quat3 = fpsCam->getCamera()->getOrientation();

now i call the shoot functiona nd pass in the vector of the character, quat of the camera, and scene

rayne->shootBullet(vec, quat3, mScene);

so this is what my shoot function looks like


void PlayerState::shootBullet(Ogre::Vector3 playerPos, Ogre::Quaternion playerQuat, nxOgre::scene *scen/*, Ogre::SceneManager *sm, Ogre::SceneNode *sn*/)
{
Ogre::Vector3 pPos = playerPos + Vector3(0, 20, -100);
Ogre::Quaternion quat = playerQuat;

myNamespace::writeV("pPos position.log", pPos);
myNamespace::writeQ("quat position.log", quat);

Vector3 dir = pPos + (quat * Vector3(0, 0, -2));

myNamespace::writeV("dir position.log", dir);

mProjs = scen->createBody("bullet" + Ogre::StringConverter::toString(count++), "RayneAni.mesh",new cubeShape(20),10,dir);
mProjs->setIgnoreGravity(true);
//mProjs->setAngularDamping(20);
//mProjs->setLinearDamping(20);
mProjs->freezeRotation(Vector3(1, 1, 1));
//mProjs->freezeMovement(Vector3(1, 1, 0));
//mProjs->mActor->setLinearVelocity(NxVec3(0, 0, 1000));
mProjs->mActor->setLinearVelocity(NxVec3(quat.x, quat.y, quat.z));
//mProjs->addForce(dir.x, dir.y, dir.z);

}

now the commented out stuff is some of the stuff i have been trying .. but nothing seems to make it fire directly out .. also witht he dir .. i beleive i found it somewhere on the forms .. that was suppose to get the proper spot to fire from .. not sure if it is working lol .. nothing seems to be atm .. anyone have any suggestions?