JNR
laStaticModel.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 #ifndef M_STATIC_MODEL_H
30 #define M_STATIC_MODEL_H
31 
33 
34 
40 
41 #define M_SNAP_RANGE (M_UNIT*0.05)
42 #define M_SNAP_RANGE_Z (M_UNIT*0.05)
43 
44 class laStaticModel: public laModel /*, public laLoadableObj*/
45 {
46 protected:
47  M_BOOL _bLightweightInstance; // Object desn't own the vertex arrays, it only holds pointers
48 
49  laPoint3 *_arFlatVertex;
50  laPoint3 *_arFlatNormal;
51  laPoint2 *_arFlatTex;
52  unsigned _nFlatVertex;
53 
54  inline void _draw_traingles(laRenderer *pr);
55  inline void _bend(laPoint3 *arv, laPoint3 *arn);
56  inline void _rotate(laPoint3 *arv, laPoint3 *arn);
57  inline void _offset(laPoint3 *arv, laPoint3 *arn);
58 
59  void _cache_save(FILE* f);
60  void _cache_load(FILE* f);
61 
62  friend class laStateObject;
63  friend class laAnimatedModel;
64 
65 public:
66  laStaticModel(void);
67  ~laStaticModel(void);
68 
69  // Instantiate
70  // Note that this method desn't copy vertex data but shares it with another static model
71  // This method is used by laAnimatedModel for blending animations without wasting memory
72  //
73  void instantiate(laStaticModel* pInstanceOf) {
74  _bLightweightInstance = M_TRUE;
75 
76  _arFlatVertex = pInstanceOf->_arFlatVertex;
77  _arFlatNormal = pInstanceOf->_arFlatNormal;
78  _arFlatTex = pInstanceOf->_arFlatTex;
79 
80  _nFlatVertex = pInstanceOf->_nFlatVertex;
81 
82  _nTex = pInstanceOf->_nTex;
83  _bEmissive = pInstanceOf->_bEmissive;
84  _nShininess = pInstanceOf->_nShininess;
85  }
86 
87  inline bool isLightweight() { return _bLightweightInstance; }
88 
89  virtual char* strTexture() { return _strTex; };
90  virtual unsigned vertexCount() { return _nFlatVertex; };
91 
92  virtual laPoint3 boundaryMin();
93  virtual laPoint3 boundaryMax();
94 
95  void create(unsigned nFaceCnt);
96  virtual bool load(char* strFile);
97  virtual void load(class laFileParser *fp, unsigned nf, unsigned nv, unsigned ntv); // no cache load
98  virtual void discard();
99 
100  virtual void buildCollisionData(class laCollisionDomain* pDomain, rpgTrap* pTrap=NULL);
101 
102  // Edit geometry
103  // NOTE: These methods are slow and should be used only at loading time
104  //
105  virtual void edScale(laPoint3 sz);
106  virtual void edTranslate(laPoint3 pos);
107  virtual void edNormalize();
108  virtual void edMinaxis();
109  virtual void edMaxaxis();
110  virtual void edCentralize();
111  virtual void edSnap();
112  virtual void edSortZ();
113 
114  // Draw
115  //
116  virtual void draw(laRenderer *pr);
117  virtual void drawFx(laRenderer *pr) {};
118 };
120 #endif
2D Point
Definition: laPoint_novec.h:41
Animated 3D Model.
Abstract Interface for 3D Models.
Definition: laModel.h:38
Multi-state Level Object.
Definition: laStateObject.h:64
Trap Properties.
Definition: rpgTrap.h:42
Collision Domain.
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
Static 3D Model.
Definition: laStaticModel.h:44
File Parser.
Definition: laFileParser.h:41