00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef PRIMITIVE_RENDERER_H_
00026 #define PRIMITIVE_RENDERER_H_
00027
00028 #include <Graphics/System/GraphicsDeviceObjectHolder.h>
00029 #include <Core/Container/ArrayList.h>
00030 #include <Graphics/PrimitiveRenderer/PrimitiveDrawRequest.h>
00031
00032 namespace Lamp{
00033
00034 class Camera;
00035
00036
00037
00038
00039
00040 class PrimitiveRenderer : public GraphicsDeviceObjectHolder{
00041 public:
00042
00043
00044
00045
00046
00047
00048 PrimitiveRenderer();
00049
00050
00051
00052
00053 virtual ~PrimitiveRenderer();
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 virtual void render(const Matrix44& viewMatrix,
00064 const Matrix44& projectionMatrix);
00065
00066
00067
00068
00069
00070 virtual void render(Camera* camera);
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 virtual void request(const PrimitiveDrawRequest& primitive,
00083 const Matrix34& matrix, Color4c color = Color4c::white,
00084 bool zTest = true);
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 virtual void request(const PrimitiveDrawRequest& primitive,
00096 const Vector3& scale, const Vector3& rotationXYZ,
00097 const Vector3 translation, Color4c color = Color4c::white,
00098 bool zTest = true){
00099 Matrix34 matrix;
00100 matrix.setTransformationXYZ(scale, rotationXYZ, translation);
00101 request(primitive, matrix, color, zTest);
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 virtual void request(const PrimitiveDrawRequest& primitive,
00114 const Vector3& scale, const Quaternion& rotationQuaternion,
00115 const Vector3 translation, Color4c color = Color4c::white,
00116 bool zTest = true){
00117 Matrix34 matrix;
00118 matrix.setTransformationQuaternion(
00119 scale, rotationQuaternion, translation);
00120 request(primitive, matrix, color, zTest);
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 virtual void requestLine(int vertexCount, Vector3* positions,
00133 const Matrix34& matrix, Color4c color = Color4c::white,
00134 bool zTest = true);
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 virtual void requestLine(int vertexCount, Vector3* positions,
00147 const Vector3& scale, const Vector3& rotationXYZ,
00148 const Vector3 translation, Color4c color = Color4c::white,
00149 bool zTest = true){
00150 Matrix34 matrix;
00151 matrix.setTransformationXYZ(scale, rotationXYZ, translation);
00152 requestLine(vertexCount, positions, matrix, color, zTest);
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 virtual void requestLine(int vertexCount, Vector3* positions,
00166 const Vector3& scale, const Quaternion& rotationQuaternion,
00167 const Vector3 translation, Color4c color = Color4c::white,
00168 bool zTest = true){
00169 Matrix34 matrix;
00170 matrix.setTransformationQuaternion(
00171 scale, rotationQuaternion, translation);
00172 requestLine(vertexCount, positions, matrix, color, zTest);
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 virtual void requestLine(int vertexCount, Vector3* positions,
00186 Color4c* colors, const Matrix34& matrix,
00187 Color4c color = Color4c::white, bool zTest = true);
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 virtual void requestLine(int vertexCount, Vector3* positions,
00201 Color4c* colors, const Vector3& scale, const Vector3& rotationXYZ,
00202 const Vector3 translation, Color4c color = Color4c::white,
00203 bool zTest = true){
00204 Matrix34 matrix;
00205 matrix.setTransformationXYZ(scale, rotationXYZ, translation);
00206 requestLine(vertexCount, positions, colors, matrix, color, zTest);
00207 }
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 virtual void requestLine(int vertexCount, Vector3* positions,
00221 Color4c* colors, const Vector3& scale,
00222 const Quaternion& rotationQuaternion, const Vector3 translation,
00223 Color4c color = Color4c::white, bool zTest = true){
00224 Matrix34 matrix;
00225 matrix.setTransformationQuaternion(
00226 scale, rotationQuaternion, translation);
00227 requestLine(vertexCount, positions, colors, matrix, color, zTest);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 virtual void requestPoint(const Matrix34& matrix,
00240 Color4c color = Color4c::white, bool zTest = true){
00241 request(point_, matrix, color, zTest);
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 virtual void requestPoint(const Vector3& scale,
00253 const Vector3& rotationXYZ, const Vector3 translation,
00254 Color4c color = Color4c::white, bool zTest = true){
00255 request(point_, scale, rotationXYZ, translation, color, zTest);
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 virtual void requestPoint(const Vector3& scale,
00267 const Quaternion& rotationQuaternion, const Vector3 translation,
00268 Color4c color = Color4c::white, bool zTest = true){
00269 request(point_, scale, rotationQuaternion, translation, color, zTest);
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279 virtual void requestAxisPoint(const Matrix34& matrix,
00280 Color4c color = Color4c::white, bool zTest = true){
00281 request(axisAxisPoint_, matrix, color, zTest);
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 virtual void requestAxisPoint(const Vector3& scale,
00293 const Vector3& rotationXYZ, const Vector3 translation,
00294 Color4c color = Color4c::white, bool zTest = true){
00295 request(axisAxisPoint_, scale, rotationXYZ, translation, color, zTest);
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 virtual void requestAxisPoint(const Vector3& scale,
00307 const Quaternion& rotationQuaternion, const Vector3 translation,
00308 Color4c color = Color4c::white, bool zTest = true){
00309 request(axisAxisPoint_, scale, rotationQuaternion, translation, color, zTest);
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319 virtual void requestAxis(const Matrix34& matrix,
00320 Color4c color = Color4c::white, bool zTest = true){
00321 request(axis_, matrix, color, zTest);
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 virtual void requestAxis(const Vector3& scale,
00333 const Vector3& rotationXYZ, const Vector3 translation,
00334 Color4c color = Color4c::white, bool zTest = true){
00335 request(axis_, scale, rotationXYZ, translation, color, zTest);
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 virtual void requestAxis(const Vector3& scale,
00347 const Quaternion& rotationQuaternion, const Vector3 translation,
00348 Color4c color = Color4c::white, bool zTest = true){
00349 request(axis_, scale, rotationQuaternion, translation, color, zTest);
00350 }
00351
00352
00353
00354
00355
00356
00357
00358
00359 virtual void requestArrow(const Matrix34& matrix,
00360 Color4c color = Color4c::white, bool zTest = true){
00361 request(arrow_, matrix, color, zTest);
00362 }
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 virtual void requestArrow(const Vector3& scale,
00373 const Vector3& rotationXYZ, const Vector3 translation,
00374 Color4c color = Color4c::white, bool zTest = true){
00375 request(arrow_, scale, rotationXYZ, translation, color, zTest);
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 virtual void requestArrow(const Vector3& scale,
00387 const Quaternion& rotationQuaternion, const Vector3 translation,
00388 Color4c color = Color4c::white, bool zTest = true){
00389 request(arrow_, scale, rotationQuaternion, translation, color, zTest);
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399 virtual void requestGrid(const Matrix34& matrix,
00400 Color4c color = Color4c::white, bool zTest = true){
00401 request(grid_, matrix, color, zTest);
00402 }
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412 virtual void requestGrid(const Vector3& scale,
00413 const Vector3& rotationXYZ, const Vector3 translation,
00414 Color4c color = Color4c::white, bool zTest = true){
00415 request(grid_, scale, rotationXYZ, translation, color, zTest);
00416 }
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 virtual void requestGrid(const Vector3& scale,
00427 const Quaternion& rotationQuaternion, const Vector3 translation,
00428 Color4c color = Color4c::white, bool zTest = true){
00429 request(grid_, scale, rotationQuaternion, translation, color, zTest);
00430 }
00431
00432
00433
00434
00435
00436
00437
00438
00439 virtual void requestPlane(const Matrix34& matrix,
00440 Color4c color = Color4c::white, bool zTest = true){
00441 request(plane_, matrix, color, zTest);
00442 }
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 virtual void requestPlane(const Vector3& scale,
00453 const Vector3& rotationXYZ, const Vector3 translation,
00454 Color4c color = Color4c::white, bool zTest = true){
00455 request(plane_, scale, rotationXYZ, translation, color, zTest);
00456 }
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 virtual void requestPlane(const Vector3& scale,
00467 const Quaternion& rotationQuaternion, const Vector3 translation,
00468 Color4c color = Color4c::white, bool zTest = true){
00469 request(plane_, scale, rotationQuaternion, translation, color, zTest);
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479 virtual void requestSphere(const Matrix34& matrix,
00480 Color4c color = Color4c::white, bool zTest = true){
00481 request(sphere_, matrix, color, zTest);
00482 }
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 virtual void requestSphere(const Vector3& scale,
00493 const Vector3& rotationXYZ, const Vector3 translation,
00494 Color4c color = Color4c::white, bool zTest = true){
00495 request(sphere_, scale, rotationXYZ, translation, color, zTest);
00496 }
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 virtual void requestSphere(const Vector3& scale,
00507 const Quaternion& rotationQuaternion, const Vector3 translation,
00508 Color4c color = Color4c::white, bool zTest = true){
00509 request(sphere_, scale, rotationQuaternion, translation, color, zTest);
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519 virtual void requestBox(const Matrix34& matrix,
00520 Color4c color = Color4c::white, bool zTest = true){
00521 request(box_, matrix, color, zTest);
00522 }
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532 virtual void requestBox(const Vector3& scale,
00533 const Vector3& rotationXYZ, const Vector3 translation,
00534 Color4c color = Color4c::white, bool zTest = true){
00535 request(box_, scale, rotationXYZ, translation, color, zTest);
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 virtual void requestBox(const Vector3& scale,
00547 const Quaternion& rotationQuaternion, const Vector3 translation,
00548 Color4c color = Color4c::white, bool zTest = true){
00549 request(box_, scale, rotationQuaternion, translation, color, zTest);
00550 }
00551
00552
00553
00554
00555
00556
00557
00558
00559 virtual void requestCylinder(const Matrix34& matrix,
00560 Color4c color = Color4c::white, bool zTest = true){
00561 request(cylinder_, matrix, color, zTest);
00562 }
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572 virtual void requestCylinder(const Vector3& scale,
00573 const Vector3& rotationXYZ, const Vector3 translation,
00574 Color4c color = Color4c::white, bool zTest = true){
00575 request(cylinder_, scale, rotationXYZ, translation, color, zTest);
00576 }
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 virtual void requestCylinder(const Vector3& scale,
00587 const Quaternion& rotationQuaternion, const Vector3 translation,
00588 Color4c color = Color4c::white, bool zTest = true){
00589 request(cylinder_, scale, rotationQuaternion, translation,
00590 color, zTest);
00591 }
00592
00593
00594
00595
00596
00597
00598
00599
00600 virtual void requestCone(const Matrix34& matrix,
00601 Color4c color = Color4c::white, bool zTest = true){
00602 request(cone_, matrix, color, zTest);
00603 }
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613 virtual void requestCone(const Vector3& scale,
00614 const Vector3& rotationXYZ, const Vector3 translation,
00615 Color4c color = Color4c::white, bool zTest = true){
00616 request(cone_, scale, rotationXYZ, translation, color, zTest);
00617 }
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 virtual void requestCone(const Vector3& scale,
00628 const Quaternion& rotationQuaternion, const Vector3 translation,
00629 Color4c color = Color4c::white, bool zTest = true){
00630 request(cone_, scale, rotationQuaternion, translation, color, zTest);
00631 }
00632
00633
00634
00635
00636
00637
00638
00639
00640 virtual bool initializeGraphicsDeviceObjects(){ return true; }
00641
00642
00643
00644
00645 virtual void deleteGraphicsDeviceObjects(){}
00646
00647
00648
00649
00650
00651 virtual bool restoreGraphicsDeviceObjects(){ return true; }
00652
00653
00654
00655
00656 virtual void invalidateGraphicsDeviceObjects();
00657
00658 protected:
00659
00660
00661
00662
00663
00664
00665 class Request{
00666 public:
00667
00668
00669
00670 Request() : matrix_(Matrix34::unit), primitive_(),
00671 color_(Color4c::white), zTest_(true){}
00672
00673
00674
00675
00676 virtual ~Request(){}
00677
00678
00679 Matrix34 matrix_;
00680
00681 PrimitiveDrawRequest primitive_;
00682
00683 Color4c color_;
00684
00685 bool zTest_;
00686 };
00687
00688
00689
00690
00691
00692 virtual void renderRequest(Request& request);
00693
00694
00695
00696
00697
00698
00699
00700
00701 void setPositionVertexDeclaration();
00702
00703
00704
00705
00706
00707 void setPositionColorVertexDeclaration();
00708
00709
00710 ArrayList<Request> requests_;
00711
00712 Direct3DVertexDeclaration* positionDeclaration_;
00713
00714 Direct3DVertexDeclaration* positionColorDeclaration_;
00715
00716 PrimitiveDrawRequest point_;
00717
00718 PrimitiveDrawRequest axisAxisPoint_;
00719
00720 PrimitiveDrawRequest axis_;
00721
00722 PrimitiveDrawRequest arrow_;
00723
00724 PrimitiveDrawRequest grid_;
00725
00726 PrimitiveDrawRequest plane_;
00727
00728 PrimitiveDrawRequest sphere_;
00729
00730 PrimitiveDrawRequest box_;
00731
00732 PrimitiveDrawRequest cone_;
00733
00734 PrimitiveDrawRequest cylinder_;
00735
00736 private:
00737
00738 PrimitiveRenderer(const PrimitiveRenderer& copy);
00739
00740
00741 void operator =(const PrimitiveRenderer& copy);
00742
00743 };
00744
00745
00746 }
00747 #endif // End of PRIMITIVE_RENDERER_H_
00748
00749