Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/src/libraries/tools/bsp/Q3Map_Bezier.cpp @ 12177

Last change on this file since 12177 was 12177, checked in by siramesh, 5 years ago

Super Orxo Bros Final (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 3.0 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// Bezier.cpp -- tessellates the Bezier patches
23
24/* The tessellation code is taken from the document
25"Rendering Quake 3 Maps" at
26http://graphics.cs.brown.edu/games/quake/quake3.html
27The author states that it is based on code from
28Paul Baker's Octagon project,
29http://www.paulsprojects.net/opengl/octagon/octagon.html
30which is released under the New BSD license.
31Please see the licenses folder.
32*/
33
34#include "Q3Map_Bezier.h"
35#include "Q3Map_misc.h"
36
37
38Bezier::Bezier()
39{       
40  mVertex = 0;
41  mIndex = 0;
42  mTrianglesPerRow = 0;
43  mRowIndex = 0;
44}
45
46Bezier::~Bezier()
47{
48  DELETE_ARRAY(mVertex);
49  DELETE_ARRAY(mIndex);
50  DELETE_ARRAY(mTrianglesPerRow);
51  DELETE_ARRAY(mRowIndex);
52}
53
54
55
56
57
58void Bezier::tessellate(int L) 
59{
60  // The number of vertices along a side is 1 + num edges
61  const int L1 = L + 1;
62
63  mVertex = new BspVertex[L1*L1];
64  mNumVertex = L1*L1;
65
66  // Compute the vertices   
67  for (int i = 0; i <= L; ++i)
68  {
69    float a = (float)i / L;
70    float b = 1.0f - a;
71
72    mVertex[i] =
73      mControls[0] * (b * b) + 
74      mControls[3] * (2 * b * a) +
75      mControls[6] * (a * a);
76  }
77
78  for (int i = 1; i <= L; i++) 
79  {
80    float a = (float)i / L;
81    float b = 1.0f - a;
82
83    BspVertex temp[3];
84
85    for (int j = 0; j < 3; j++)
86    {
87      int k = 3 * j;
88      temp[j] =
89        mControls[k + 0] * (b * b) + 
90        mControls[k + 1] * (2 * b * a) +
91        mControls[k + 2] * (a * a);
92    }
93
94    for(int j = 0; j <= L; ++j) 
95    {
96      float a = (float)j / L;
97      float b = 1.0f - a;
98
99      mVertex[i * L1 + j]=
100        temp[0] * (b * b) + 
101        temp[1] * (2 * b * a) +
102        temp[2] * (a * a);
103    }
104  }
105
106  // Compute the indices     
107  mIndex = new unsigned int[L * (L + 1) * 2];
108  mNumIndex = L * (L + 1) * 2;
109
110  for (int row = 0; row < L; ++row) 
111  {
112    for(int col = 0; col <= L; ++col)   
113    {
114      mIndex[(row * (L + 1) + col) * 2 + 1] = row       * L1 + col;
115      mIndex[(row * (L + 1) + col) * 2]     = (row + 1) * L1 + col;
116    }
117  }
118
119  mTrianglesPerRow = new unsigned int[L];
120  mRowIndex = new unsigned int[L];
121
122  for (int row = 0; row < L; ++row) 
123  {
124    mTrianglesPerRow[row] = 2 * L1;
125    //rowIndexes[row]      = &indexes[row * 2 * L1];
126    mRowIndex[row]      = row * 2 * L1;
127  }
128
129  for (int i=0; i < L1*L1; i++)
130    mVertex[i].normalise();
131}
Note: See TracBrowser for help on using the repository browser.