1// tInstance.h 
2// 
3// This file implements tScene instances. An instance is essentially a transformation (position, rotation, scale) in 
4// addition to a reference to the object being instanced. In a tScene, this reference consists of the ID of a 
5// particular type of object. 
6// 
7// Copyright (c) 2006, 2017 Tristan Grimmer. 
8// Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby 
9// granted, provided that the above copyright notice and this permission notice appear in all copies. 
10// 
11// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 
12// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 
13// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
14// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
15// PERFORMANCE OF THIS SOFTWARE. 
16 
17#pragma once 
18#include "Scene/tObject.h" 
19namespace tScene 
20
21 
22 
23class tInstance : public tObject 
24
25public
26 tInstance() { } 
27 tInstance(const tChunk& chunk) { Load(chunk); } 
28 virtual ~tInstance() { } 
29 
30 void Clear() { tObject::Clear(); ObjectType = tType::Unspecified; ObjectID = tObject::InvalidID; Transform.Identity(); } 
31 bool IsValid() const { return (ObjectType != tType::Unspecified) ? true : false; } 
32 
33 // This does not scale the object itself because when a world is scaled, the object being referred to is also 
34 // scaled. Here we just need to scale the translation. 
35 void Scale(float scale) { tMath::tMul(Transform.C4, scale); Transform.C4.w = 1.0f; } 
36 
37 void Save(tChunkWriter&) const
38 void Load(const tChunk&); 
39 
40 enum class tType 
41
42 Unspecified = -1
43 PolyModel
44 PatchModel
45 LodGroup
46 Camera
47 Light
48 Path
49 NumTypes 
50 }; 
51 
52 // This is the type and ID of the object being instanced. 
53 tType ObjectType = tType::Unspecified
54 uint32 ObjectID = tObject::InvalidID
55 
56 // This is the transform of the instance. Places it in the world at a particular position, scale, and orientation. 
57 tMath::tMatrix4 Transform = tMath::tMatrix4::identity
58}; 
59 
60 
61
62