Debian Codegraph @

source/unix/odesrc/OPCODE/OPC_BaseModel.cpp

raw
1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 /*
3 * OPCODE - Optimized Collision Detection
4 * Copyright (C) 2001 Pierre Terdiman
5 * Homepage: http://www.codercorner.com/Opcode.htm
6 */
7 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8
9 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10 /**
11 * Contains base model interface.
12 * \file OPC_BaseModel.cpp
13 * \author Pierre Terdiman
14 * \date May, 18, 2003
15 */
16 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
17
18 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19 /**
20 * The base class for collision models.
21 *
22 * \class BaseModel
23 * \author Pierre Terdiman
24 * \version 1.3
25 * \date May, 18, 2003
26 */
27 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
28
29 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30 // Precompiled Header
31 #include "Stdafx.h"
32
33 using namespace Opcode;
34
35 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
36 /**
37 * Constructor.
38 */
39 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40 BaseModel::BaseModel() : mIMesh(null), mModelCode(0), mSource(null), mTree(null)
41 {
42 }
43
44 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45 /**
46 * Destructor.
47 */
48 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49 BaseModel::~BaseModel()
50 {
51 ReleaseBase();
52 }
53
54 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55 /**
56 * Releases everything.
57 */
58 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59 void BaseModel::ReleaseBase()
60 {
61 DELETESINGLE(mSource);
62 DELETESINGLE(mTree);
63 }
64
65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66 /**
67 * Creates an optimized tree according to user-settings, and setups mModelCode.
68 * \param no_leaf [in] true for "no leaf" tree
69 * \param quantized [in] true for quantized tree
70 * \return true if success
71 */
72 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 bool BaseModel::CreateTree(bool no_leaf, bool quantized)
74 {
75 DELETESINGLE(mTree);
76
77 // Setup model code
78 if(no_leaf) mModelCode |= OPC_NO_LEAF;
79 else mModelCode &= ~OPC_NO_LEAF;
80
81 if(quantized) mModelCode |= OPC_QUANTIZED;
82 else mModelCode &= ~OPC_QUANTIZED;
83
84 // Create the correct class
85 if(mModelCode & OPC_NO_LEAF)
86 {
87 if(mModelCode & OPC_QUANTIZED) mTree = new AABBQuantizedNoLeafTree;
88 else mTree = new AABBNoLeafTree;
89 }
90 else
91 {
92 if(mModelCode & OPC_QUANTIZED) mTree = new AABBQuantizedTree;
93 else mTree = new AABBCollisionTree;
94 }
95 CHECKALLOC(mTree);
96
97 return true;
98 }
99
100 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101 /**
102 * Refits the collision model. This can be used to handle dynamic meshes. Usage is:
103 * 1. modify your mesh vertices (keep the topology constant!)
104 * 2. refit the tree (call this method)
105 * \return true if success
106 */
107 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
108 bool BaseModel::Refit()
109 {
110 // Refit the optimized tree
111 return mTree->Refit(mIMesh);
112
113 // Old code kept for reference : refit the source tree then rebuild !
114 // if(!mSource) return false;
115 // // Ouch...
116 // mSource->Refit(&mTB);
117 // // Ouch...
118 // return mTree->Build(mSource);
119 }