[Opentnl-cvs] tnl/zap CTFGame.cpp,1.15,1.16 ship.cpp,1.17,1.18 ship.h,1.9,1.10 sparkManager.cpp,1.3,
Brought to you by:
mark_frohnmayer,
s_alanet
From: Ben G. <s_a...@us...> - 2004-04-30 08:33:41
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16526/zap Modified Files: CTFGame.cpp ship.cpp ship.h sparkManager.cpp sparkManager.h Log Message: Added fxTrail motion trail helper class. Added ship motion trails based on position/orientation of ship. Small cleanups. Index: sparkManager.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sparkManager.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sparkManager.h 26 Apr 2004 05:22:43 -0000 1.2 --- sparkManager.h 30 Apr 2004 08:33:20 -0000 1.3 *************** *** 44,47 **** --- 44,76 ---- }; + class fxTrail + { + private: + struct TrailNode + { + Point pos; + S32 ttl; + }; + + Vector<TrailNode> mNodes; + + U32 mDropFreq; + U32 mLength; + + public: + fxTrail(U32 dropFrequency = 32, U32 len = 15); + + /// Update the point this trail is attached to. + void update(Point pos); + + void tick(U32 dT); + + void render(); + + void reset(); + + Point getLastPos(); + }; + }; Index: ship.h =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ship.h 27 Apr 2004 22:36:48 -0000 1.9 --- ship.h 30 Apr 2004 08:33:20 -0000 1.10 *************** *** 29,32 **** --- 29,33 ---- #include "moveObject.h" + #include "sparkManager.h" namespace Zap *************** *** 56,68 **** FireDelay = 100, MaxControlObjectInterpDistance = 200, }; enum MaskBits { ! InitialMask = BIT(0), ! PositionMask = BIT(1), ! MoveMask = BIT(2), ! WarpPositionMask = BIT(3), ! ExplosionMask = BIT(4), ! HealthMask = BIT(5), }; --- 57,70 ---- FireDelay = 100, MaxControlObjectInterpDistance = 200, + TrailCount = 2, }; enum MaskBits { ! InitialMask = BIT(0), ! PositionMask = BIT(1), ! MoveMask = BIT(2), ! WarpPositionMask = BIT(3), ! ExplosionMask = BIT(4), ! HealthMask = BIT(5), }; *************** *** 72,75 **** --- 74,80 ---- StringTableEntry mPlayerName; + S32 mLastTrailPoint[TrailCount]; + fxTrail mTrail[TrailCount]; + Color color; // color of the ship F32 mass; // mass of ship Index: CTFGame.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/CTFGame.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** CTFGame.cpp 28 Apr 2004 01:10:32 -0000 1.15 --- CTFGame.cpp 30 Apr 2004 08:33:20 -0000 1.16 *************** *** 216,219 **** --- 216,220 ---- s2cSetTeamScore(cl.teamId, mTeams[cl.teamId].score); s2cCTFMessage(CTFMsgCaptureFlag, cl.name, mountedFlag->getTeamIndex()); + // score the flag for the client's team... mountedFlag->dismount(); Index: sparkManager.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/sparkManager.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sparkManager.cpp 26 Apr 2004 05:22:43 -0000 1.3 --- sparkManager.cpp 30 Apr 2004 08:33:20 -0000 1.4 *************** *** 166,168 **** --- 166,233 ---- }; + fxTrail::fxTrail(U32 dropFrequency, U32 len) + { + mDropFreq = dropFrequency; + mLength = len; + } + + void fxTrail::update(Point pos) + { + if(mNodes.size() < mLength) + { + TrailNode t; + t.pos = pos; + t.ttl = mDropFreq; + + mNodes.push_front(t); + } + else + mNodes[0].pos = pos; + } + + void fxTrail::tick(U32 dT) + { + if(mNodes.size() == 0) + return; + + mNodes.last().ttl -= dT; + if(mNodes.last().ttl <= 0) + mNodes.pop_back(); + } + + void fxTrail::render() + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glBegin(GL_LINE_STRIP); + + for(S32 i=0; i<mNodes.size(); i++) + { + F32 t = ((F32)i/(F32)mNodes.size()); + glColor4f(1.f - 2*t, 1.f - 2*t, 1.f, 1.f-t); + glVertex2f(mNodes[i].pos.x, mNodes[i].pos.y); + } + + glEnd(); + + glDisable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ZERO); + } + + void fxTrail::reset() + { + mNodes.clear(); + } + + Point fxTrail::getLastPos() + { + if(mNodes.size()) + { + return mNodes[0].pos; + } + else + return Point(0,0); + } + }; \ No newline at end of file Index: ship.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ship.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ship.cpp 27 Apr 2004 23:26:15 -0000 1.17 --- ship.cpp 30 Apr 2004 08:33:20 -0000 1.18 *************** *** 66,69 **** --- 66,72 ---- mPlayerName = playerName; + + for(S32 i=0; i<TrailCount; i++) + mTrail[i].reset(); } *************** *** 181,184 **** --- 184,191 ---- // Emit some particles emitMovementSparks(); + + for(U32 i=0; i<TrailCount; i++) + mTrail[i].tick(theMove->time); + SFXObject::setListenerParams(mMoveState[RenderState].pos, mMoveState[RenderState].vel); } *************** *** 191,194 **** --- 198,204 ---- // Emit some particles emitMovementSparks(); + + for(U32 i=0; i<TrailCount; i++) + mTrail[i].tick(deltaT); } *************** *** 287,291 **** --- 297,306 ---- Point delta = mMoveState[ActualState].pos - mMoveState[RenderState].pos; if(delta.len() > MaxControlObjectInterpDistance) + { + for(S32 i=0; i<TrailCount; i++) + mTrail[i].reset(); + interpTime = 0; + } else interpTime = 1; *************** *** 407,410 **** --- 422,428 ---- interpTime = 0; mMoveState[RenderState] = mMoveState[ActualState]; + + for(S32 i=0; i<TrailCount; i++) + mTrail[i].reset(); } } *************** *** 445,449 **** // Scope for all ships on our team. ! for(U32 i=0; i<gt->mClientList.size(); i++) { if(gt->mClientList[i].teamId == teamId) --- 463,467 ---- // Scope for all ships on our team. ! for(S32 i=0; i<gt->mClientList.size(); i++) { if(gt->mClientList[i].teamId == teamId) *************** *** 540,590 **** void Ship::emitMovementSparks() { ! // draw thrusters ! Point velDir(lastMove.right - lastMove.left, lastMove.down - lastMove.up); ! F32 len = velDir.len(); ! F32 thrusts[4]; ! for(U32 i = 0; i < 4; i++) ! thrusts[i] = 0; ! if(len > 0) { ! if(len > 1) ! velDir *= 1 / len; ! Point shipDirs[4]; ! shipDirs[0].set(sin(mMoveState[RenderState].angle), cos(mMoveState[RenderState].angle) ); ! shipDirs[1].set(-shipDirs[0]); ! shipDirs[2].set(shipDirs[0].y, -shipDirs[0].x); ! shipDirs[3].set(-shipDirs[0].y, shipDirs[0].x); ! for(U32 i = 0; i < 4; i++) { ! thrusts[i] = shipDirs[i].dot(velDir); ! if(thrusts[i] > 0.1) ! { ! // shoot some sparks... ! if(thrusts[i] >= 2*TNL::Random::readF() * velDir.len()) ! { ! Point chaos(TNL::Random::readF(),TNL::Random::readF()); ! chaos *= 5; ! //interp give us some nice enginey colors... ! Color dim(1, 0, 0); ! Color light(1, 1, 0); ! Color thrust; ! F32 t = TNL::Random::readF(); ! thrust.interp(t, dim, light); ! SparkManager::emitSpark( ! mMoveState[RenderState].pos - shipDirs[i] * 13, ! -shipDirs[i] * (F32)(1.f - mMoveState[RenderState].vel.len() * (1.f/(F32)MaxVelocity)) * 100 + chaos, ! thrust ! ); ! } ! } ! } } } --- 558,646 ---- void Ship::emitMovementSparks() { ! // Do nothing if we're under 0.001 vel ! if(hasExploded || mMoveState[ActualState].vel.len() < 0.1) ! return; ! Point corners[3]; ! Point shipDirs[3]; ! ! corners[0].set(-20, -15); ! corners[1].set( 0, 25); ! corners[2].set( 20, -15); ! ! F32 th = mMoveState[RenderState].angle; ! ! F32 sinTh = sin(th); ! F32 cosTh = cos(th); ! ! for(S32 i=0; i<3; i++) { ! shipDirs[i].x = corners[i].x * cosTh + corners[i].y * sinTh; ! shipDirs[i].y = corners[i].y * cosTh - corners[i].x * sinTh; ! } ! Point leftVec ( mMoveState[ActualState].vel.y, -mMoveState[ActualState].vel.x); ! Point rightVec(-mMoveState[ActualState].vel.y, mMoveState[ActualState].vel.x); ! leftVec.normalize(); ! rightVec.normalize(); ! ! S32 bestId = -1, leftId, rightId; ! F32 bestDot = -1; ! ! // Find the left-wards match ! for(S32 i = 0; i < 3; i++) ! { ! F32 d = leftVec.dot(shipDirs[i]); ! if(d >= bestDot) { ! bestDot = d; ! bestId = i; ! } ! } ! leftId = bestId; ! Point leftPt = mMoveState[RenderState].pos + shipDirs[bestId]; ! // Find the right-wards match ! bestId = -1; ! bestDot = -1; ! ! for(S32 i = 0; i < 3; i++) ! { ! F32 d = rightVec.dot(shipDirs[i]); ! if(d >= bestDot) ! { ! bestDot = d; ! bestId = i; ! } ! } ! rightId = bestId; ! Point rightPt = mMoveState[RenderState].pos + shipDirs[bestId]; ! // Stitch things up if we must... ! if(leftId == mLastTrailPoint[0] && rightId == mLastTrailPoint[1]) ! { ! mTrail[0].update(leftPt); ! mTrail[1].update(rightPt); ! mLastTrailPoint[0] = leftId; ! mLastTrailPoint[1] = rightId; } + else if(leftId == mLastTrailPoint[1] && rightId == mLastTrailPoint[0]) + { + mTrail[1].update(leftPt); + mTrail[0].update(rightPt); + mLastTrailPoint[1] = leftId; + mLastTrailPoint[0] = rightId; + } + else + { + mTrail[0].update(leftPt); + mTrail[1].update(rightPt); + mLastTrailPoint[0] = leftId; + mLastTrailPoint[1] = rightId; + } + } *************** *** 594,597 **** --- 650,656 ---- return; + for(U32 i=0; i<TrailCount; i++) + mTrail[i].render(); + if(posSegments.size()) { |