-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarLoader.cpp
executable file
·98 lines (72 loc) · 2.09 KB
/
CarLoader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// CarLoader.cpp: implementation of the CarLoader class.
//
// Copyright (2005) Gideon Pertzov
//
// This source code is provided "AS IS" without express or implied warranties.
// You may use this source code in FREEWARE applications you distribute,
// Provided that credit is given to the original author.
// You MAY NOT use the source code in ANY COMMERCIAL APPLICATION
// Without the written consent of the original author.
//
// http://www.gpdev.net
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
#include "Mmgr\mmgr.h"
#endif
#include "CarLoader.h"
#define CAR_FILE_CUR_HDR "NeuroDriverCarFile"
#define CAR_FILE_CUR_VER 2
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CarLoader::CarLoader() : _pVisuals(NULL),
_pPhysics(NULL)
{
}
CarLoader::~CarLoader()
{
}
int CarLoader::validateDoc()
{
if (strcmp(_pRoot->Value(), CAR_FILE_CUR_HDR) != 0)
return -1;
// check version
int ver;
if (_pRoot->Attribute("version", &ver) == NULL)
return -1;
if (ver != CAR_FILE_CUR_VER)
return -1;
// get Visuals element
_pVisuals = (TiXmlElement*)_pRoot->FirstChild("Visuals");
if (_pVisuals == NULL)
return -1;
// get Physics element
_pPhysics = (TiXmlElement*)_pRoot->FirstChild("Physics");
if (_pPhysics == NULL)
return -1;
return 0;
}
double CarLoader::getPhysicsAttr(const char* attrName)
{
if (_pPhysics == NULL)
return 0;
TiXmlElement* pElem = (TiXmlElement*)_pPhysics->FirstChild(attrName);
if (pElem == NULL)
return 0;
double val = atof(pElem->FirstChild()->Value());
return val;
}
const char* CarLoader::getMeshPath()
{
if (_pVisuals == NULL)
return NULL;
TiXmlElement* pModelPath = (TiXmlElement*)_pVisuals->FirstChild("mesh");
if (pModelPath == NULL)
return NULL;
return ( pModelPath->FirstChild()->Value() );
}