Jump to content

Search the Community

Showing results for tags 'GUN HAND NPC XML C++'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Blogs

  • Development Blog
  • Canardian's Blog
  • Beyond Civilization Blog Ext
  • Tyler's Blog
  • macklebee's Blog
  • B-Byrnes' Blog
  • Marleys Ghost's Blog
  • omid3098's Blog
  • Richardsimpo123456's Blog
  • DJDD's Blog
  • Rick's Blog
  • --
  • xtreampb's Blog
  • Economically Disadvantaged
  • klepto2's Blog
  • Old Blog
  • Chris Paulson's Blog
  • Davaris' Blog
  • nil
  • Rekindled Phoenix's Blog
  • Flexman's Blog
  • Kattemaksu Online
  • Marcousik's Creations Blog
  • EVE LBS Studio
  • Rendering puzzles
  • Screen Size Utility
  • Niosop's Blog
  • 1299 RTS Game Project
  • Blitzbat's Blog
  • gordonramp's Blog
  • Andy Gilbert's Blog
  • Marcus' Blog
  • JornAggror Blog
  • diedir's Blog
  • wayneg's Blog
  • Masterxilo's Blog
  • Dave Lee's Blog
  • peubuy's blog
  • OD Arts -Leadwerks Blog
  • The progression......
  • Ultra Software Company Blog
  • The Progression
  • Pancake's Blog
  • Test Blog
  • BLaBZ Blog
  • Pure³d's Blog
  • dreamhead Blog
  • RVL's Blog
  • DB's Blog
  • Toxin Games Development Blog
  • CombatHelo Blog (RSS Import)
  • Foolish's Blog
  • ZioRed's Corner
  • Toxin Games Twitter
  • Shard - Third Initiative
  • Shard's Blog
  • Soamp's Blog
  • Soamp's Blog
  • Laurens' Blog
  • JT`s warehouse district
  • Kennar's Blog
  • KiteFuchs' Blog
  • KiteFuchs' Blog
  • Rachel's Dev-Blog
  • Eagle's Blog
  • zaphos' Blog
  • please delete this blog
  • Afke's Blog
  • Richard Simpson
  • knowledgegranted's Blog
  • EdzUp(GD)'s Blog
  • aGameLife's Kelasel MMORPG Blog
  • tournamentdan's Blog
  • Beyond Civilization Blog
  • smashthewindow
  • AnniXa's Blog
  • AnniXa's Blog
  • Elemental Development
  • DigitalHax Blog
  • Aria's Blog
  • Strogg76's Blog
  • Clackdor's Blog
  • Leadwerks Project Status
  • simpleprogrammer's Blog
  • Pathfinding in LE.2.x
  • Naughty Alien's Blog
  • smashthewindow's Blog
  • Ali Salehi's Blog
  • Jardar's Blog
  • Chris Vossen's Development Blog
  • Scarlet Thread Studios' Blog
  • Kronos' Blog
  • Benton's Blog
  • ChrisV's Blog
  • tjheldna's Blog
  • shadmar's Blog
  • 3D Masons, LLC
  • Andy Gilbert's Enviro Models
  • ParaToxic's Blog
  • NarkLord's Blog
  • ChrisMAN's Blog
  • ChrisMAN's Blog
  • CGMan's Blog
  • The Game
  • Chris Tutorials
  • Leadwerks 3 Experience
  • An Alien Saga
  • klepto2 & Leadwerks 3
  • Inside the mind of eternal insomniac
  • josk's Blog
  • Shader Development in Leadwerks 3.1
  • 3D Coat : Column game making of
  • Einlander's Blog
  • Ginger George's Blog
  • I have a problem
  • Michael_J's Blog
  • nasamydifol's Blog
  • Digman's Blog
  • noesisGUI
  • SavageDogg38's Blog
  • Built from Ruins
  • Remaining Days
  • test_external_blog
  • The Hunt For Food Blog
  • Crazy Minnow Studio
  • CrazyMinnowStudio
  • Guppy's Blog
  • Playing Online
  • Evayr's Blog
  • DerRidda's Blog
  • Karl's Blog
  • whiterabbit's Blog
  • Tinyboss Games
  • abendkleider's Blog
  • sacguccireplica's Blog
  • Arena
  • Imchasinyou's Blog
  • xtom's Blog
  • Lua is better than you think.
  • mdgunn's Blog
  • Crime Closer
  • lxFirebal69xl's Blog
  • Wedmer's Blog
  • Lockdown, going forward.
  • Pump-Action Captain
  • Igor's Blog
  • Dead Anyway
  • Runenrise and more
  • reepblue's Blog
  • Slippy's Corner
  • LUA Musings
  • severjack's Blog
  • mikeporter's Blog
  • miko93's Blog
  • Megalocerous' Blog
  • lxFirebal69xl's Blog
  • aiaf's Blog
  • Lostghbear's Blog
  • echo $BLOG_NAME > blog_title.tmpl
  • johnadam111's Blog
  • Dwarf Beard
  • burgelkat's Blog
  • Charrua's Blog
  • peterpaul's Blog
  • joshmathews' Blog
  • Martin Kearl's Blog
  • Brutile's blog
  • tipforeveryone's Blog
  • Glushchenko Blog
  • Express Lab Games Blog
  • Blueapples' Blog
  • DooMAGE's Blog
  • Structura devblog
  • UltraEngine - Experiences, add-ons and other Stuff
  • martyj's Blog
  • Dragonfreak's Blog
  • Brutile's Blog
  • assigmenthelp
  • Case Study Assignment Help
  • How to deal with bad grade ?
  • How to deal with bad grade ?
  • GameDev Blog
  • devcjohnson's Blog
  • devcjohnson's Blog
  • THE WHAT? Blog
  • The Demurian Scribe
  • GUI Editor
  • GUI Tutorial
  • noob_shaders
  • The Seventh World
  • Phodex Games Blog
  • Leadwerks VS Source 2
  • Work in Progress - Scifi PBR Media
  • [C++] First Player game start
  • The Blog of Yue
  • Snowboarding Development Blog
  • Ocean: Rendering in Leadwerks 4
  • Game Ready Maps
  • Ultra App Kit (Advanced Custom Widgets)
  • Poking around
  • Blender tutorials
  • Usefull Scripts & Components
  • Thirsty Panther
  • Ultimate Action Game Controller

Forums

  • Software
    • General Discussion
    • Programming
    • Game Artwork
    • Showcase
    • Suggestion Box
    • Bug Reports
  • Addons
    • Extensions & Plugins
    • Components
    • Addon Development
  • Platforms
    • Windows
    • Linux
    • macOS

Categories

  • Streams and Events
  • Tutorials
  • Games
  • Work in Progress

Categories

  • Components
  • Effects
  • Extensions
  • Materials
    • Asphalt
    • Brick
    • Concrete
    • Debris
    • Effects
    • Fabric
    • Ground
    • Marble
    • Metal
    • Organic
    • Plaster
    • Rock
    • Roof
    • Sand
    • Snow
    • Surface Imperfections
    • Tile
    • Wood
  • Models
    • Animals & Creatures
    • Architecture
    • Food
    • Machinery
    • Plants and Vegetation
    • Props
    • Vehicles
  • Scenes
  • Skyboxes
  • Tools

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location

Found 1 result

  1. Placing a rifle to sit in the hands of an NPC can be a bit of a fiddle so I thought I'd post the code. The code relies on bones for accurate placement:- Trigger bone Gun Butt/Rest bone Trigger hand Butt hand I place config stuff like this in an XML file for easy editting, to read the XML I use a nice library tinyXML. Ignore the bullet code as this is a temp hack I will tidy later. Hope this helps. PS Thanks to Pixel Perfect for supplying gun model etc for my testing, without him I'd be "assetless". #include "gun/include/gun.h" #include "gun/include/bullet.h" #include "gamelib.h" //#define DEBUG_GUN_POS ActorGun::ActorGun( TScene *pScene, string pFile, TEntity par, TEntity spine, TEntity pTrig, TEntity pRest ): m_fireRate(300), m_range(50) { m_lastFireTime = AppTime(); m_scene = pScene; m_scene->framewerk.GetMain().SetWorld(); m_entity = LoadModel( (char *)pFile.c_str() ); m_spine = spine; m_parent = par; EntityType(m_entity, 5,1); EntityParent( m_entity, m_parent); m_handTrigger = pTrig; m_handRest = pRest; HookUpdateEvent(m_scene->updateEvent); #ifdef DEBUG_GUN_POS HookRenderEvent(m_scene->renderEvent); #endif } bool ActorGun::withinRange( float pDist ) { return (pDist <= m_range); } void ActorGun::Render( float gameLoopTime) { #ifdef DEBUG_GUN_POS TVec3 trigPos = EntityPosition( m_handTrigger, 1); TVec3 restPos = EntityPosition( m_handRest, 1); TVec3 trigBonePos = EntityPosition( m_triggerBone, 1); TVec3 restBonePos = EntityPosition( m_restBone, 1); SetColor( Vec4(1,0,0,1) ); // red tdDraw( m_scene->cam, trigPos, Vec3( trigPos.X, trigPos.Y + 0.1, trigPos.Z) ); SetColor( Vec4(0,0,1,1) ); // blue tdDraw( m_scene->cam, restPos, Vec3( restPos.X, restPos.Y + 0.1, restPos.Z) ); SetColor( Vec4(0,1,0,1) ); // green tdDraw( m_scene->cam, trigBonePos, Vec3( trigBonePos.X, trigBonePos.Y - 0.1, trigBonePos.Z) ); SetColor( Vec4(1,1,1,1) ); // white tdDraw( m_scene->cam, restBonePos, Vec3( restBonePos.X, restBonePos.Y - 0.1, restBonePos.Z) ); TVec3 pos = EntityPosition(m_muzzelBone,1); TVec3 pos1 = TFormVector( Vec3(0,0,-1), m_spine, NULL); pos1.X += pos.X; pos1.Y += pos.Y; pos1.Z += pos.Z; tdDraw( m_scene->cam, pos, pos1 ); #endif } // Position the gun in the actors hand void ActorGun::Update(float gameLoopTime) { TVec3 trigPos; TVec3 restPos = EntityPosition( m_handRest, 1); TVec3 handPos = EntityPosition( m_handTrigger, 1); float diffx = handPos.X - restPos.X; float diffy = handPos.Y - restPos.Y; float diffz = handPos.Z - restPos.Z; AlignToVector( m_entity, Vec3(diffx,diffy,diffz),3 ); TVec3 pos = EntityPosition(m_entity,1); trigPos = EntityPosition(m_triggerBone,1); diffx = pos.X - trigPos.X; diffy = pos.Y - trigPos.Y; diffz = pos.Z - trigPos.Z; trigPos = EntityPosition( m_handTrigger, 1); trigPos.X += diffx; trigPos.Y += diffy; trigPos.Z += diffz; PositionEntity(m_entity, trigPos, 1); list<Bullet*>::iterator bulletList; for(bulletList = m_bullets.begin(); bulletList != m_bullets.end(); ) { if ((*bulletList)->m_life == 0) { delete *bulletList; m_bullets.erase( bulletList++ ); } else ++bulletList; } } bool ActorGun::fireGun() { if (AppTime() < m_lastFireTime ) return false; m_lastFireTime = AppTime() + m_fireRate; Bullet *bullet; TVec3 pos; pos = EntityPosition(m_muzzelBone,1); //bullet = new Bullet( pos, TFormVector( Vec3(0,0,-1), m_muzzelBone, NULL), m_scene ); bullet = new Bullet( pos, TFormVector( Vec3(0,0,-1), m_spine, NULL), m_scene ); m_bullets.push_back( bullet ); return true; } TEntity gunPickSource; int _stdcall gunFilter( TEntity entity ) { if ( isParent(gunPickSource, entity) ) return 0; return 1; } bool ActorGun::canHit( TEntity target, TVec3 tagetPos) { gunPickSource = m_entity; TVec3 pos = EntityPosition(m_muzzelBone,1); TPick pick; if (LinePick( &pick, pos, tagetPos, 0, 0, (BP)gunFilter)) { if (isParent(target, pick.entity )) return true; } else return true; return false; } // Read in gun information from an XML file bool ActorGun::readGunFile( string pFile ) { string filename; string typeName; string bone; filename = AbstractPath( (str)pFile.c_str()); TiXmlDocument doc( filename.c_str() ); TiXmlElement* child = 0; TiXmlElement *bones = 0; doc.LoadFile( filename.c_str() ); bones = doc.FirstChildElement("bones"); if(bones) { child = bones->FirstChildElement(); while(child) { typeName = child->Attribute("type"); if(typeName == "trigger") { m_triggerBone = FindChild( m_entity, (str)child->Attribute("name") ); m_triggerPos = EntityPosition( m_triggerBone ); } typeName = child->Attribute("type"); if(typeName == "rest") { m_restBone = FindChild( m_entity, (str)child->Attribute("name") ); m_restPos = EntityPosition( m_restBone ); } if(typeName == "muzzel") { m_muzzelBone = FindChild( m_entity, (str)child->Attribute("name") ); } child = child->NextSiblingElement(); } } return true; } Include: - #ifndef GUN_H #define GUN_H #include "tinyxml.h" #include "gamelib/include/scene.h" #include "event/include/gameEvent.h" #include "gun/include/bullet.h" #include <list> class ActorGun : public GameObject { protected: TScene *m_scene; public: TEntity m_parent; TEntity m_entity; TEntity m_actor; TEntity m_handTrigger; TEntity m_handRest; TEntity m_triggerBone; TEntity m_restBone; TEntity m_muzzelBone; TEntity m_spine; TVec3 m_triggerPos; TVec3 m_restPos; list<Bullet*> m_bullets; float m_fireRate; float m_lastFireTime; float m_range; ActorGun( TScene *pScene, std::string pFile, TEntity par, TEntity spine, TEntity pTrig, TEntity pRest ); virtual void Update( float gameLoopTime); virtual void Render( float gameLoopTime); bool fireGun(); bool withinRange( float pDist ); bool canHit( TEntity target, TVec3 tagetPos); bool readGunFile( std::string pFile ); }; #endif
×
×
  • Create New...