[prev in list] [next in list] [prev in thread] [next in thread]
List: bzflag-commits
Subject: SF.net SVN: bzflag: [16637] trunk/bzflag/src/bzflag
From: jannejun () users ! sourceforge ! net
Date: 2008-02-20 23:43:06
Message-ID: E1JRyaf-0007Sa-Sb () sc8-pr-svn2 ! sourceforge ! net
[Download RAW message or body]
Revision: 16637
http://bzflag.svn.sourceforge.net/bzflag/?rev=16637&view=rev
Author: jannejun
Date: 2008-02-20 15:43:03 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
Added functions to predict the shot position and velocity vectors after a given time.
Modified Paths:
--------------
trunk/bzflag/src/bzflag/GuidedMissleStrategy.cxx
trunk/bzflag/src/bzflag/GuidedMissleStrategy.h
trunk/bzflag/src/bzflag/SegmentedShotStrategy.cxx
trunk/bzflag/src/bzflag/SegmentedShotStrategy.h
trunk/bzflag/src/bzflag/ShockWaveStrategy.cxx
trunk/bzflag/src/bzflag/ShockWaveStrategy.h
trunk/bzflag/src/bzflag/ShotPath.cxx
trunk/bzflag/src/bzflag/ShotPath.h
trunk/bzflag/src/bzflag/ShotStrategy.h
Modified: trunk/bzflag/src/bzflag/GuidedMissleStrategy.cxx
===================================================================
--- trunk/bzflag/src/bzflag/GuidedMissleStrategy.cxx 2008-02-20 22:36:45 UTC (rev \
16636)
+++ trunk/bzflag/src/bzflag/GuidedMissleStrategy.cxx 2008-02-20 23:43:03 UTC (rev \
16637) @@ -261,6 +261,141 @@
setVelocity(newDirection);
}
+bool GuidedMissileStrategy::predictPosition(float dt, float p[3]) const
+{
+ float v[3];
+ return _predict(dt, p, v);
+}
+
+bool GuidedMissileStrategy::predictVelocity(float dt, float v[3]) const
+{
+ float p[3];
+ return _predict(dt, p, v);
+}
+
+bool GuidedMissileStrategy::_predict(float dt, float p[3], float v[3]) const
+{
+ const bool isRemote = (getPath().getPlayer() !=
+ LocalPlayer::getMyTank()->getId());
+
+ float ctime = currentTime + dt;
+
+ /*
+ * If it expires there we'll return false.
+ */
+ if (ctime - getPath().getStartTime() >= getPath().getLifetime())
+ return false;
+
+ // get target
+ const Player* target = NULL;
+ if (isRemote)
+ {
+ if (lastTarget != NoPlayer)
+ target = lookupPlayer(lastTarget);
+ }
+ else
+ {
+ LocalPlayer* myTank = LocalPlayer::getMyTank();
+ if (myTank)
+ target = myTank->getTarget();
+ }
+
+ if ((target != NULL) && ((target->getFlag() == Flags::Stealth) || \
((target->getStatus() & short(PlayerState::Alive)) == 0))) + target = NULL;
+
+ float tmpAzimuth = azimuth, tmpElevation = elevation;
+ // compute next segment's ray
+ if (target)
+ {
+ // turn towards target
+ // find desired direction
+ const float* targetPos = target->getPosition();
+ float desiredDir[3];
+ desiredDir[0] = targetPos[0] - nextPos[0];
+ desiredDir[1] = targetPos[1] - nextPos[1];
+ desiredDir[2] = targetPos[2] - nextPos[2];
+ desiredDir[2] += target->getMuzzleHeight(); // right between the eyes
+
+ // compute desired angles
+ float newAzimuth = atan2f(desiredDir[1], desiredDir[0]);
+ float newElevation = atan2f(desiredDir[2], hypotf(desiredDir[1], \
desiredDir[0])); +
+ float gmissileAng = BZDB.eval(StateDatabase::BZDB_GMTURNANGLE);
+
+ // compute new azimuth
+ float deltaAzimuth = limitAngle(newAzimuth - azimuth);
+ if (fabsf(deltaAzimuth) <= dt * gmissileAng)
+ tmpAzimuth = limitAngle(newAzimuth);
+ else if (deltaAzimuth > 0.0f)
+ tmpAzimuth = limitAngle(azimuth + dt * gmissileAng);
+ else
+ tmpAzimuth = limitAngle(azimuth - dt * gmissileAng);
+
+ // compute new elevation
+ float deltaElevation = limitAngle(newElevation - elevation);
+ if (fabsf(deltaElevation) <= dt * gmissileAng)
+ tmpElevation = limitAngle(newElevation);
+ else if (deltaElevation > 0.0f)
+ tmpElevation = limitAngle(elevation + dt * gmissileAng);
+ else
+ tmpElevation = limitAngle(elevation - dt * gmissileAng);
+ }
+
+ float newDirection[3];
+ newDirection[0] = cosf(tmpAzimuth) * cosf(tmpElevation);
+ newDirection[1] = sinf(tmpAzimuth) * cosf(tmpElevation);
+ newDirection[2] = sinf(tmpElevation);
+ Ray ray = Ray(nextPos, newDirection);
+
+ // get next position
+ float shotSpeed = BZDB.eval(StateDatabase::BZDB_SHOTSPEED);
+ ray.getPoint(dt * shotSpeed, p);
+
+ // see if we hit something
+ if (p[2] <= 0.0f)
+ return false;
+ else
+ {
+ // see if we hit a building
+ float t = float((currentTime - prevTime) * shotSpeed);
+ int face;
+ const Obstacle* building = getFirstBuilding(ray, Epsilon, t);
+ const Teleporter* teleporter = getFirstTeleporter(ray, Epsilon, t, face);
+
+ World *world = World::getWorld();
+ if (!world) {
+ return false;
+ }
+
+ // check in reverse order to see what we hit first
+ if (teleporter) {
+ // entered teleporter -- teleport it
+ unsigned int seed = getPath().getShotId();
+ int source = world->getTeleporter(teleporter, face);
+ int teletarget = world->getTeleportTarget(source, seed);
+
+ int outFace;
+ const Teleporter* outTeleporter = world->getTeleporter(teletarget, outFace);
+ teleporter->getPointWRT(*outTeleporter, face, outFace, p, NULL, tmpAzimuth, p, \
NULL, &tmpAzimuth); + } else if (building) {
+ // expire on next update
+ return false;
+ }
+ }
+
+ // update shot
+ newDirection[0] *= shotSpeed;
+ newDirection[1] *= shotSpeed;
+ newDirection[2] *= shotSpeed;
+
+ v[0] = newDirection[0];
+ v[1] = newDirection[1];
+ v[2] = newDirection[2];
+
+ return true;
+}
+
+
float GuidedMissileStrategy::checkBuildings(const Ray& ray)
{
float shotSpeed = BZDB.eval(StateDatabase::BZDB_SHOTSPEED);
Modified: trunk/bzflag/src/bzflag/GuidedMissleStrategy.h
===================================================================
--- trunk/bzflag/src/bzflag/GuidedMissleStrategy.h 2008-02-20 22:36:45 UTC (rev \
16636)
+++ trunk/bzflag/src/bzflag/GuidedMissleStrategy.h 2008-02-20 23:43:03 UTC (rev \
16637) @@ -35,6 +35,9 @@
~GuidedMissileStrategy();
void update(float dt);
+ bool predictPosition(float dt, float p[3]) const;
+ bool predictVelocity(float dt, float p[3]) const;
+
float checkHit(const ShotCollider&, float[3]) const;
void sendUpdate(const FiringInfo&) const;
void readUpdate(uint16_t, void*);
@@ -44,6 +47,7 @@
private:
float checkBuildings(const Ray& ray);
+ bool _predict(float dt, float p[3], float v[3]) const;
private:
double prevTime;
Modified: trunk/bzflag/src/bzflag/SegmentedShotStrategy.cxx
===================================================================
--- trunk/bzflag/src/bzflag/SegmentedShotStrategy.cxx 2008-02-20 22:36:45 UTC (rev \
16636)
+++ trunk/bzflag/src/bzflag/SegmentedShotStrategy.cxx 2008-02-20 23:43:03 UTC (rev \
16637) @@ -168,6 +168,39 @@
}
}
+bool SegmentedShotStrategy::predictPosition(float dt, float p[3]) const
+{
+ float ctime = currentTime + dt;
+ int cur=0;
+ // see if we've moved to another segment
+ const int numSegments = (const int)segments.size();
+ while (cur < numSegments && segments[cur].end < ctime) cur++;
+ if (cur >= numSegments) return false;
+
+ segments[segment].ray.getPoint(float(ctime - segments[segment].start), p);
+
+ return true;
+}
+
+
+bool SegmentedShotStrategy::predictVelocity(float dt, float p[3]) const
+{
+ float ctime = currentTime + dt;
+ int cur=0;
+ // see if we've moved to another segment
+ const int numSegments = (const int)segments.size();
+ while (cur < numSegments && segments[cur].end < ctime) cur++;
+ if (cur >= numSegments) return false;
+
+ const float *pos;
+ pos = segments[segment].ray.getDirection();
+
+ p[0] = pos[0]; p[1] = pos[1]; p[2] = pos[2];
+
+ return true;
+}
+
+
void SegmentedShotStrategy::setCurrentTime(const
double _currentTime)
{
Modified: trunk/bzflag/src/bzflag/SegmentedShotStrategy.h
===================================================================
--- trunk/bzflag/src/bzflag/SegmentedShotStrategy.h 2008-02-20 22:36:45 UTC (rev \
16636)
+++ trunk/bzflag/src/bzflag/SegmentedShotStrategy.h 2008-02-20 23:43:03 UTC (rev \
16637) @@ -36,6 +36,8 @@
~SegmentedShotStrategy();
void update(float dt);
+ bool predictPosition(float dt, float p[3]) const;
+ bool predictVelocity(float dt, float p[3]) const;
float checkHit(const ShotCollider&, float[3]) const;
void addShot(SceneDatabase*, bool colorblind);
void radarRender() const;
Modified: trunk/bzflag/src/bzflag/ShockWaveStrategy.cxx
===================================================================
--- trunk/bzflag/src/bzflag/ShockWaveStrategy.cxx 2008-02-20 22:36:45 UTC (rev 16636)
+++ trunk/bzflag/src/bzflag/ShockWaveStrategy.cxx 2008-02-20 23:43:03 UTC (rev 16637)
@@ -99,7 +99,31 @@
if (radius >= BZDB.eval(StateDatabase::BZDB_SHOCKOUTRADIUS)) setExpired();
}
+bool ShockWaveStrategy::predictPosition(float dt, float p[3]) const
+{
+ float r = radius + dt * (BZDB.eval(StateDatabase::BZDB_SHOCKOUTRADIUS) - \
BZDB.eval(StateDatabase::BZDB_SHOCKINRADIUS)) / getPath().getLifetime(); + if (r >= \
BZDB.eval(StateDatabase::BZDB_SHOCKOUTRADIUS)) return false;
+ const float *pos = getPath().getPosition();
+ p[0] = pos[0];
+ p[1] = pos[1];
+ p[2] = pos[2];
+ return true;
+}
+
+bool ShockWaveStrategy::predictVelocity(float dt, float p[3]) const
+{
+ float r = radius + dt * (BZDB.eval(StateDatabase::BZDB_SHOCKOUTRADIUS) - \
BZDB.eval(StateDatabase::BZDB_SHOCKINRADIUS)) / getPath().getLifetime(); + if (r >= \
BZDB.eval(StateDatabase::BZDB_SHOCKOUTRADIUS)) return false; +
+ p[0] = (BZDB.eval(StateDatabase::BZDB_SHOCKOUTRADIUS) - \
BZDB.eval(StateDatabase::BZDB_SHOCKINRADIUS)) / getPath().getLifetime(); + p[1] = 0;
+ p[2] = 0;
+
+ return true;
+}
+
+
float ShockWaveStrategy::checkHit(const ShotCollider& tank, float position[3]) const
{
// return if player is inside radius of destruction -- note that a
Modified: trunk/bzflag/src/bzflag/ShockWaveStrategy.h
===================================================================
--- trunk/bzflag/src/bzflag/ShockWaveStrategy.h 2008-02-20 22:36:45 UTC (rev 16636)
+++ trunk/bzflag/src/bzflag/ShockWaveStrategy.h 2008-02-20 23:43:03 UTC (rev 16637)
@@ -31,6 +31,8 @@
~ShockWaveStrategy();
void update(float dt);
+ bool predictPosition(float dt, float p[3]) const;
+ bool predictVelocity(float dt, float p[3]) const;
float checkHit(const ShotCollider&, float[3]) const;
bool isStoppedByHit() const;
void addShot(SceneDatabase*, bool colorblind);
Modified: trunk/bzflag/src/bzflag/ShotPath.cxx
===================================================================
--- trunk/bzflag/src/bzflag/ShotPath.cxx 2008-02-20 22:36:45 UTC (rev 16636)
+++ trunk/bzflag/src/bzflag/ShotPath.cxx 2008-02-20 23:43:03 UTC (rev 16637)
@@ -157,6 +157,16 @@
reloadTime += dt;
}
+bool ShotPath::predictPosition(float dt, float p[3]) const
+{
+ return getStrategy()->predictPosition(dt, p);
+}
+
+bool ShotPath::predictVelocity(float dt, float p[3]) const
+{
+ return getStrategy()->predictVelocity(dt, p);
+}
+
//
// LocalShotPath
//
Modified: trunk/bzflag/src/bzflag/ShotPath.h
===================================================================
--- trunk/bzflag/src/bzflag/ShotPath.h 2008-02-20 22:36:45 UTC (rev 16636)
+++ trunk/bzflag/src/bzflag/ShotPath.h 2008-02-20 23:43:03 UTC (rev 16637)
@@ -72,6 +72,10 @@
virtual void update(float) {};
+ //This function can be used to predict the position of the shot after a given time \
dt. Function returns true iff. the shot is still alive. + bool \
predictPosition(float dt, float p[3]) const; + bool predictVelocity(float dt, \
float p[3]) const; +
protected:
ShotPath(const FiringInfo&, double);
void updateShot(float dt);
Modified: trunk/bzflag/src/bzflag/ShotStrategy.h
===================================================================
--- trunk/bzflag/src/bzflag/ShotStrategy.h 2008-02-20 22:36:45 UTC (rev 16636)
+++ trunk/bzflag/src/bzflag/ShotStrategy.h 2008-02-20 23:43:03 UTC (rev 16637)
@@ -57,6 +57,8 @@
virtual ~ShotStrategy();
virtual void update(float dt) = 0;
+ virtual bool predictPosition(float dt, float p[3]) const = 0;
+ virtual bool predictVelocity(float dt, float p[3]) const = 0;
virtual float checkHit(const ShotCollider&, float[3])const = 0;
virtual bool isStoppedByHit() const;
virtual void addShot(SceneDatabase*, bool colorblind) = 0;
This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
BZFlag-commits mailing list
BZFlag-commits@lists.SourceForge.net
https://lists.SourceForge.net/lists/listinfo/bzflag-commits
irc: #BZFlag @ irc.freenode.net
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic