Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/tools/bsp/Q3Map_BspVertex.cpp @ 11152

Last change on this file since 11152 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1/*
2===========================================================================
3Copyright (C) 2008 Daniel Örstadius
4
5This file is part of bsp-renderer source code.
6
7bsp-renderer is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12bsp-renderer is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with bsp-renderer.  If not, see <http://www.gnu.org/licenses/>.
19
20*/
21
22// BspVertex.cpp -- used in the tessellation of the Bezier patches
23
24
25#include <math.h>
26#include "Q3Map_BspVertex.h"
27
28
29BspVertex::BspVertex()
30{
31  for (int i=0; i<3; i++)
32    mPosition[i] = 0;
33
34  for (int i=0; i<3; i++)
35    mNormal[i] = 0;
36
37  for(int i=0; i<2; i++)
38    for(int j=0; j<2; j++)
39      mTexcoord[i][j] = 0;
40}
41
42BspVertex::BspVertex(float p[3], float texcoord[2][2], float n[3])
43{
44  for (int i=0; i<3; i++)
45    mPosition[i] = p[i];
46
47  for (int i=0; i<3; i++)
48    mNormal[i] = n[i];
49
50  for(int i=0; i<2; i++)
51    for(int j=0; j<2; j++)
52    {           
53      this->mTexcoord[i][j] = texcoord[i][j];
54    }
55}
56
57BspVertex BspVertex::operator+(BspVertex a)
58{
59  BspVertex res;
60
61  for (int i=0; i<3; i++)
62  {
63    res.mPosition[i] = this->mPosition[i] + a.mPosition[i];
64    res.mNormal[i] = this->mNormal[i] + a.mNormal[i];
65  }
66
67  for(int i=0; i<2; i++)
68    for(int j=0; j<2; j++)
69    {                   
70      res.mTexcoord[i][j] = this->mTexcoord[i][j] + a.mTexcoord[i][j];
71    }
72
73    return res;
74}
75
76BspVertex BspVertex::operator*(float a)
77{
78  BspVertex res;
79
80  for (int i=0; i<3; i++)
81  {
82    res.mPosition[i] = this->mPosition[i] * a;
83    res.mNormal[i] = this->mNormal[i] * a;
84  }
85
86  for(int i=0; i<2; i++)
87    for(int j=0; j<2; j++)
88      res.mTexcoord[i][j] = this->mTexcoord[i][j] * a;
89
90  return res;
91}
92
93void BspVertex::normalise(void)
94{
95  //QVECTOR n((float)mNormal[0], (float)mNormal[1], (float)mNormal[2]);
96
97  //D3DXVec3Normalize(&n, &n);
98  //mNormal[0] = n.x;
99  //mNormal[1] = n.y;
100  //mNormal[2] = n.z;
101
102        float flLen=sqrt( mNormal[0]*mNormal[0] + mNormal[1]*mNormal[1] + mNormal[2]*mNormal[2] ) ;
103        mNormal[0]/=flLen ;
104        mNormal[1]/=flLen ;
105        mNormal[2]/=flLen ;
106}
Note: See TracBrowser for help on using the repository browser.