~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/ogreopcode/src/BP_Endpoint.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* SOLID - Software Library for Interference Detection
 
3
* Copyright (c) 2001 Dtecta <gino@dtecta.com>
 
4
*
 
5
* All rights reserved.
 
6
*/
 
7
 
 
8
#include <assert.h>
 
9
#include <new>
 
10
#include "BP_Endpoint.h"
 
11
#include "BP_Proxy.h"
 
12
#include "BP_Scene.h"
 
13
 
 
14
namespace OgreOpcode
 
15
{
 
16
        namespace Details
 
17
        {
 
18
 
 
19
                BP_Endpoint::BP_Endpoint(Ogre::Real pos, Type type, BP_Proxy *proxy, 
 
20
                        GEN_List& endpointList) :
 
21
                m_pos(pos), m_type(type), m_proxy(proxy)
 
22
                {
 
23
                        GEN_Link *next = endpointList.getHead();
 
24
 
 
25
                        while (!next->isTail() && (*(BP_Endpoint *)next < *this)) {
 
26
                                next = next->getNext();
 
27
                        }
 
28
                        insertBefore(next);             
 
29
                }
 
30
 
 
31
                BP_Endpoint::~BP_Endpoint()
 
32
                { 
 
33
                        if (m_proxy != 0) {
 
34
                                remove();
 
35
                        }
 
36
                }
 
37
 
 
38
                void encounters(const BP_Endpoint& a, const BP_Endpoint& b,
 
39
                        BP_Scene& scene,        T_Overlap overlap)
 
40
                {
 
41
                        assert(a.m_proxy != b.m_proxy);
 
42
 
 
43
                        if ((a.m_type != b.m_type) && overlap(*a.m_proxy, *b.m_proxy)) {
 
44
                                if (a.m_type == BP_Endpoint::MAXIMUM) {
 
45
                                        scene.callBeginOverlap(a.m_proxy->getObject(), 
 
46
                                                b.m_proxy->getObject());
 
47
                                }
 
48
                                else {
 
49
                                        scene.callEndOverlap(a.m_proxy->getObject(), 
 
50
                                                b.m_proxy->getObject());
 
51
                                }
 
52
                        }
 
53
                }
 
54
 
 
55
                void BP_Endpoint::move(Ogre::Real x, BP_Scene& scene, T_Overlap overlap)
 
56
                {
 
57
                        int sign = MT_sign(x - m_pos);
 
58
 
 
59
                        m_pos = x;
 
60
 
 
61
                        switch (sign) {
 
62
        case -1: {
 
63
                GEN_Link *prev = getPrev();
 
64
                if (!prev->isHead() && (*this < *(BP_Endpoint *)prev)) {
 
65
                        remove();
 
66
                        do {
 
67
                                encounters(*(BP_Endpoint *)prev, *this, scene, overlap);
 
68
                                prev = prev->getPrev();
 
69
                        }
 
70
                        while (!prev->isHead() && (*this < *(BP_Endpoint *)prev));
 
71
                        insertAfter(prev);
 
72
                }
 
73
                break;
 
74
                         }
 
75
        case 1: {
 
76
                GEN_Link *next = getNext();
 
77
                if (!next->isTail() && (*(BP_Endpoint *)next < *this)) {
 
78
                        remove();
 
79
                        do {
 
80
                                encounters(*this, *(BP_Endpoint *)next, scene, overlap);
 
81
                                next = next->getNext();
 
82
                        }
 
83
                        while (!next->isTail() && (*(BP_Endpoint *)next < *this));
 
84
                        insertBefore(next);   
 
85
                }
 
86
                break;
 
87
                        }
 
88
        case 0:
 
89
                // nothing to do 
 
90
                break;
 
91
        default:
 
92
                assert(false);
 
93
                        }
 
94
                }
 
95
 
 
96
        }
 
97
}
 
98
 
 
99
 
 
100
 
 
101
 
 
102