Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
{$MODE OBJFPC} uses tools,vipgfx,vis,math; const v3dMaxVertex=8; type v3dVector = record x,y,z,w:single; end; v3dPoly = record v:array [0..v3dMaxVertex] of v3dVector; numVertex:dword; n:v3dVector; matNum:dword; end; v3dObject = record name:string; center:v3dVector; scale:single; position,rotation:v3dVector; polys:array of v3dPoly; translatedPolys:array of v3dPoly; numPolys:dword; end; function aVector(x,y,z:single):v3dVector; var v:v3dVector; begin v.x:=X; v.Y:=Y; v.z:=Z; v.w:=1; aVector:=v; end; procedure v3dRasterizeWire(poly:v3dPoly; color:dword); var i,ii:longint; x1,y1,x2,y2:longint; begin ii:=0; for i:=0 to poly.numVertex-1 do begin inc(ii); if ii>=poly.numVertex then ii:=0; x1:=ceil(poly.v[i].x); y1:=ceil(poly.v[i].y); x2:=ceil(poly.v[ii].x); y2:=ceil(poly.v[ii].y); drawline(vscreen,x1,y1,x2,y2,color); end; end; function v3dCreatePoly(v1,v2,v3:v3dVector):v3dPoly; var i:dword; p:v3dPoly; begin p.numVertex:=3; p.v[0]:=v1; p.v[1]:=v2; p.v[2]:=v3; v3dCreatePoly:=p; end; function v3dCreateObject(name:string; x,y,z:single):v3dObject; var o:v3dObject; begin o.name:=name; setLength(o.polys,0); setLength(o.translatedPolys,0); o.numPolys:=0; o.center:=aVector(x,y,z); o.position:=aVector(0,0,0); o.rotation:=aVector(0,0,0); o.scale:=1; v3dCreateObject:=o; end; procedure v3dAddPolyToObject(var o:v3dObject; p:v3dPoly); begin inc(o.numPolys); setLength(o.polys,o.numPolys); setLength(o.translatedPolys,o.numPolys); o.polys[o.numPolys-1]:=p; end; const width=512; height=512; fullscreen=false; var theObject:v3dObject; operator + (a,b:v3dVector):v3dVector; begin result.x:=a.x + b.x; result.y:=a.y + b.y; result.z:=a.z + b.z; result.w:=1; end; function v3dMakeProjection(v:v3dVector):v3dVector; var outV:v3dVector; centerX,centerY:longint; begin outV:=v; centerX:=vscreen.width div 2; centerY:=vscreen.height div 2; outV.x:=v.x / v.z * 256 + centerX; outV.y:=v.y / v.z * -1 * 256 + centerY; v3dMakeProjection:=outV; end; procedure v3dRenderPoly(poly:v3dPoly); var i:dword; p:v3dPoly; begin for i:=0 to poly.numVertex-1 do p.v[i]:=v3dMakeProjection(poly.v[i]); p.numVertex:=poly.numVertex; v3dRasterizeWire(p,$ffffffff); end; function v3dMovePoly(poly:v3dPoly;v:v3dVector):v3dPoly; var i:dword; begin result.numVertex:=poly.numVertex; for i:=0 to poly.numVertex-1 do result.v[i]:=Poly.v[i] + v; end; procedure v3dRenderObject(var o:v3dObject); var i,ii:dword; begin for i:=0 to o.numPolys-1 do begin o.translatedPolys[i]:=v3dMovePoly(o.Polys[i],o.position); v3dRenderPoly(o.translatedPolys[i]); end; end; const speed=0.01; var rx:single=0; ry:single=0; rz:single=0; r:single=0; mx:single=0; my:single=0; mz:single=6; procedure move; begin if KEYBOARD[KEY_T] then begin mz:=mz-speed; end; if KEYBOARD[KEY_G] then begin mz:=mz+speed; end; if KEYBOARD[KEY_UP] then begin my:=my-speed; end; if KEYBOARD[KEY_DOWN] then begin my:=my+speed; end; if KEYBOARD[KEY_LEFT] then begin mx:=mx-speed; end; if KEYBOARD[KEY_RIGHT] then begin mx:=mx+speed; end; theObject.position:=aVector(mx,my,mz); end; function cube:v3dObject; var v1,v2,v3:v3dVector; p:v3dPoly; o:v3dObject; begin o:=v3dCreateObject('box',0,0,0); v1:=aVector(-1.0,-1.0,-1.0); v2:=aVector(-1.0,-1.0, 1.0); v3:=aVector(-1.0, 1.0, 1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0, 1.0,-1.0); v2:=aVector(-1.0,-1.0,-1.0); v3:=aVector(-1.0, 1.0,-1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0,-1.0, 1.0); v2:=aVector(-1.0,-1.0,-1.0); v3:=aVector(1.0,-1.0,-1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0, 1.0,-1.0); v2:=aVector(1.0,-1.0,-1.0); v3:=aVector(-1.0,-1.0,-1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(-1.0,-1.0,-1.0); v2:=aVector(-1.0, 1.0, 1.0); v3:=aVector(-1.0, 1.0,-1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0,-1.0, 1.0); v2:=aVector(-1.0,-1.0, 1.0); v3:=aVector(-1.0,-1.0,-1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(-1.0, 1.0, 1.0); v2:=aVector(-1.0,-1.0, 1.0); v3:=aVector(1.0,-1.0, 1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0, 1.0, 1.0); v2:=aVector(1.0,-1.0,-1.0); v3:=aVector(1.0, 1.0,-1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0,-1.0,-1.0); v2:=aVector(1.0, 1.0, 1.0); v3:=aVector(1.0,-1.0, 1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0, 1.0, 1.0); v2:=aVector(1.0, 1.0,-1.0); v3:=aVector(-1.0, 1.0,-1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0, 1.0, 1.0); v2:=aVector(-1.0, 1.0,-1.0); v3:=aVector(-1.0, 1.0, 1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); v1:=aVector(1.0, 1.0, 1.0); v2:=aVector(-1.0, 1.0, 1.0); v3:=aVector(1.0,-1.0, 1.0); p:=v3dCreatePoly(v1,v2,v3); v3dAddPolyToObject(o,p); cube:=o; end; begin theObject:=cube; theObject.position.z:=10; initGFXsystem(width,height,fullscreen); initInputSystem(gfxInputMessanger); repeat fastfill(vscreen.data,vscreen.width*vscreen.height,0); move; v3dRenderObject(theObject); updateGFXsystem; updateInputSystem(gfxMessanger); until gfxDone or keyboard[KEY_ESCAPE]; finishGFXsystem; closeInputSystem; ReturnFPSstring; end. |
Administrator
Zitat
Der RCCSWU (RandomCamelCaseSomtimesWithUndersquare) Stil bricht auch mal mit den veraltet strukturierten Denkmustern und erlaubt dem Entwickler seine Kreativität zu entfalten.
Werbeanzeige