ThingCollide.cpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #include "ThingCollide.hpp"
00023 #include "CollisionComponent.hpp"
00024 #include "../schema/SimSchema.hpp"
00025 #include "../pos/Pos.hpp"
00026 #include "../thing/Actor.hpp"
00027 
00028 
00029 namespace se_core {
00030 
00031     ThingCollide
00032     ::ThingCollide(const char* name) : Object(got_THING_COLLIDE, name) {
00033     }
00034 
00035 
00036     bool ThingCollide
00037     ::isGuilty(ContactInfo& pusher, const ContactInfo& target) const {
00038         if(!pusher.cc_->didGeometryCollide(*target.cc_)) {
00039             return true;
00040         }
00041         PosComponent& pPos = pusher.cc_->posComponent();
00042         //const PosComponent& tPos = target.cc_->posComponent();
00043 
00044         Point3 pNow, pNext, t;
00045         target.cc_->bouncePoint(0, pPos.pos().worldCoor(), t);
00046         pusher.cc_->bouncePoint(0, t, pNow);
00047         pusher.cc_->bouncePoint(SCALE_RES, t, pNext);
00048 
00049         coor_double_t beforeDistance = pNow.xzDistanceSquared(t);
00050         coor_double_t distanceWithPusherMoving = pNext.xzDistanceSquared(t);
00051         if(distanceWithPusherMoving >= beforeDistance) {
00052             return false;
00053         }
00054         return true;
00055         //return isGuilty(pusher.posComponent(), target.posComponent());
00056         //return true;
00057     }
00058 
00059 
00060     bool ThingCollide
00061     ::isGuilty(CollisionComponent& pusher, const CollisionComponent& target) const {
00062         if(!pusher.didGeometryCollide(target)) {
00063             return true;
00064         }
00065         PosComponent& pPos = pusher.posComponent();
00066         //const PosComponent& tPos = target.posComponent();
00067         Point3 pNow, pNext, t;
00068         target.bouncePoint(0, pPos.pos().worldCoor(), t);
00069         pusher.bouncePoint(0, t, pNow);
00070         pusher.bouncePoint(SCALE_RES, t, pNext);
00071 
00072         coor_double_t beforeDistance = pNow.xzDistanceSquared(t);
00073         coor_double_t distanceWithPusherMoving = pNext.xzDistanceSquared(t);
00074         if(distanceWithPusherMoving >= beforeDistance) {
00075             return false;
00076         }
00077         return true;
00078         //return isGuilty(pusher.posComponent(), target.posComponent());
00079         //return true;
00080     }
00081 
00082 
00083     bool ThingCollide
00084     ::isGuilty(PosComponent& pusher, const PosComponent& target) const {
00085         // Is this thing's movement bringing it closer, or farther away?
00086         coor_double_t beforeDistance = pusher.pos().worldCoor().xzDistanceSquared(target.pos().worldCoor());
00087         coor_double_t distanceWithPusherMoving = pusher.nextPos().worldCoor().xzDistanceSquared(target.pos().worldCoor());
00088         if(distanceWithPusherMoving >= beforeDistance) {
00089             return false;
00090         }
00091         return true;
00092     }
00093 
00094 }
00095 
00096 

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:11 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo