Debian Codegraph @

editor/jaytest.cpp

raw
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <time.h>
20 #include "3d.h"
21 #include "texture.h"
22 #include "object.h"
23 #include "vector.h"
24 #include "hlsoundlib.h"
25 #include "mono.h"
26 #include "d3edit.h"
27
28 vms_vertex square_data[50] = {-5.0, 5.0, -5, 5.0, 5.0, -5, 5.0, -5.0, -5, -5.0, -5.0, -5,
29 -5.0, 5.0, 5, 5.0, 5.0, 5, 5.0, -5.0, 5, -5.0, -5.0, 5};
30
31 g3s_face SquareSides[] = {{4, {0, 1, 2, 3}}, {4, {1, 5, 6, 2}}, {4, {5, 4, 7, 6}},
32 {4, {4, 0, 3, 7}}, {4, {4, 5, 1, 0}}, {4, {3, 2, 6, 7}}};
33
34 g3s_polymodel SquareModel = {6, 8, SquareSides, square_data};
35
36 object *Square = NULL;
37 object *Square2 = NULL;
38
39 extern SoundLib SndLib;
40
41 void DrawWireframeList(grViewport *vp, g3s_point *p, int nv, ddgr_color color) {
42 g3s_point *p1, *p2;
43 int i;
44
45 for (i = 0; i < nv; i++) {
46 p1 = &p[i];
47 p2 = &p[(i + 1) % nv];
48
49 vp->line(color, p1->screenx, p1->screeny, p2->screenx, p2->screeny);
50 }
51 }
52
53 void RenderTexFrame(grViewport *my_viewport) {
54 int nv, i, t;
55 g3s_point phold[70], dhold[70], fhold[70];
56 g3s_point *plist = phold, *dlist = dhold, *flist = fhold;
57 vms_vector vpos = {0, 0, 0};
58 vms_orient vang = {0, 0, 0};
59
60 static float sx = 0, sy = 0, sz = 15, rl = 0.0;
61 static float xdir = .4;
62 static float ydir = .5;
63 static float zdir = .7;
64 static float ldir = .05;
65
66 static frame = 0;
67 static time_t oldtime = 0;
68 static int framecount = 0;
69 time_t newtime;
70
71 static char f_play_sound = 1;
72
73 framecount++;
74 g3_SetViewAngles(&vpos, &vang, 0);
75
76 newtime = time(NULL);
77 if (newtime != oldtime) {
78 mprintf_at(1, 2, 0, "%d FPS ", framecount);
79 oldtime = newtime;
80 framecount = 0;
81 }
82
83 SndLib.begin_sound_frame();
84
85 if (Square2 == NULL) {
86 if ((Square2 = AllocateObject()) == NULL)
87 return;
88 mng_LoadAllTextures();
89 D3EditState.texdlg_texture = 0;
90 }
91
92 frame++;
93 sx = sx + xdir;
94 sy = sy + ydir;
95 sz = sz + zdir;
96 rl = rl + ldir;
97
98 if (rl < 0 || rl > 1) {
99 ldir = -ldir;
100 rl = rl + ldir;
101 }
102 if (sx > 10 || sx < -10) {
103 xdir = -xdir;
104 // f_play_sound = 1;
105 }
106 if (sy > 10 || sy < -10) {
107 ydir = -ydir;
108 // f_play_sound = 1;
109 }
110 if (sz > 170 || sz < .000001) {
111 zdir = -zdir;
112 sz += zdir;
113 // f_play_sound = 1;
114 }
115
116 PositionObject(Square2, sx, sy, sz);
117 if (f_play_sound) {
118 f_play_sound = 0;
119 pos_state cur_pos;
120 cur_pos.position.x = 0;
121 cur_pos.position.y = 0;
122 cur_pos.position.z = 80;
123 SndLib.play_3d_sound(1, cur_pos, OF_LOOPED);
124 }
125 SndLib.update_listener_properties(Square2->cur_pos);
126
127 g3_BeginFrame();
128 g3_TransModelToCamera(plist, &SquareModel, Square2);
129
130 Square2->cur_pos.orientation_angles.heading += GAME_ANGLE * 3;
131 Square2->cur_pos.orientation_angles.pitch += GAME_ANGLE * 2;
132
133 Current_surface = my_viewport->lock();
134
135 for (i = 0; i < SquareModel.num_of_polys; i++) {
136
137 flist = fhold;
138 dlist = dhold;
139
140 for (t = 0; t < 4; t++)
141 fhold[t] = plist[SquareModel.faces[i].points[t]];
142
143 fhold[0].monolight = fhold[1].monolight = fhold[2].monolight = fhold[3].monolight = rl;
144
145 fhold[0].ucoord = 0;
146 fhold[0].vcoord = 0;
147 fhold[1].ucoord = 1.0;
148 fhold[1].vcoord = 0;
149 fhold[2].ucoord = 1.0;
150 fhold[2].vcoord = 1.0;
151 fhold[3].ucoord = 0;
152 fhold[3].vcoord = 1.0;
153 fhold[0].flags = fhold[1].flags = fhold[2].flags = fhold[3].flags =
154 PF_TEXTURE | PF_COLORED_LIGHTING | PF_MONO_LIGHTING;
155
156 nv = g3_CheckToClip(&flist, &dlist, 4);
157
158 if (sz > 60)
159 tex_SetRenderType(RENDERTYPE_LIN_NON_UNLIT);
160 else
161 tex_SetRenderType(RENDERTYPE_LIN_NON_UNLIT);
162
163 if (nv > 0) {
164 if (g3_ProjectPointListToCanvas(dlist, nv)) {
165 if (g3_PointsVisible(dlist, nv)) {
166 tex_TriangulatePointList(D3EditState.texdlg_texture, dlist, nv);
167 }
168 }
169 }
170 }
171
172 my_viewport->unlock();
173 SndLib.end_sound_frame();
174 }
175
176 void RenderWireFrame(grViewport *my_viewport) {
177 int nv = 4;
178 g3s_point phold[10], dhold[10];
179 g3s_point *plist = phold, *dlist = dhold;
180 static float sx = 0, sy = 0, sz = 20;
181 static float xdir = .4;
182 static float ydir = .3;
183 static float zdir = .6;
184
185 if (Square == NULL)
186 if ((Square = AllocateObject()) == NULL)
187 return;
188
189 PositionObject(Square, sx, sy, sz);
190 sx = sx + xdir;
191 sy = sy + ydir;
192 sz = sz + zdir;
193 if (sx > 10 || sx < -10)
194 xdir = -xdir;
195 if (sy > 10 || sy < -10)
196 ydir = -ydir;
197 if (sz > 50 || sz < 5)
198 zdir = -zdir;
199
200 g3_BeginFrame();
201 g3_TransVertsToCamera(plist, square_data, Square, 4);
202 nv = g3_CheckToClip(&plist, &dlist, 4);
203
204 Square->cur_pos.orientation_angles.heading += GAME_ANGLE * 2;
205 Square->cur_pos.orientation_angles.pitch += GAME_ANGLE * 2;
206
207 if (nv > 0) {
208 g3_ProjectPointListToCanvas(dlist, nv);
209 Current_surface = my_viewport->lock();
210 DrawWireframeList(my_viewport, dlist, nv, GR_RGB(255, 0, 255));
211 my_viewport->unlock();
212 }
213 }