Spatial.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_Node3D_INCLUDED
34 #define H_DC_Node3D_INCLUDED
35 
36 #include <Dynacoe/Util/Transform.h>
37 
38 namespace Dynacoe{
39 
50 class SpatialTransformUpdate;
51 class Spatial {
52  public:
53  Spatial();
54  virtual ~Spatial();
55 
56  // Gets the transform for this spatial object alone.
57  // Modifications to it affect the global transform calculations
58  inline Transform & Node() {return *node;}
59 
60  // Gets the transform matrix that represets this Transform and its
61  // child parent transforms. If changes have been queued for children
62  // transforms or this one, those changes are applied.
63  TransformMatrix & GetGlobalTransform();
64 
65  // Swaps the built in transform for the given transform
66  // pass nullptr to return the transform back to the default.
67  void ReplaceTransform(Transform *);
68 
69  // Sets the given spatial object as a child of this one
70  void SetAsParent(Spatial *);
71 
72  // invalidates this transfrom manually, causing itself and children to update
73  // upon next request for its transform.
74  void Invalidate();
75 
76  void CheckUpdate();
77 
78  //Returns a 16-float array that signifies the internal transform array.
79  //This is intended for quick renderer upload. This will always
80  //reflect the global transform
81  void UpdateModelTransforms(RenderBufferID id);
82 
83 
84 
85  protected:
86  virtual void OnUpdateTransform(){}
87 
88  private:
89  Spatial * parent;
90  std::vector<Spatial*> children;
91  Transform * transformOwned;
92  TransformMatrix global;
93  bool needsUpdate;
94  SpatialTransformUpdate * transformUpdate;
95  void SendUpdateSignal();
96  Transform * node;
97 };
98 }
99 
100 
101 
102 #endif
Definition: AssetID.h:37