55import engine .processing .LightGizmoRenderer ;
66import engine .processing .LightRendererImpl ;
77import engine .render .Material ;
8+ import engine .resources .Image ;
89import engine .scene .camera .Camera ;
910import engine .scene .light .Light ;
1011import engine .scene .light .LightRenderer ;
1415import mesh .Mesh3D ;
1516import processing .core .PApplet ;
1617import processing .core .PGraphics ;
18+ import processing .core .PImage ;
19+ import processing .opengl .PGraphicsOpenGL ;
1720import processing .opengl .PShader ;
1821import workspace .render .Mesh3DRenderer ;
1922import workspace .ui .Color ;
@@ -35,6 +38,10 @@ public class GraphicsPImpl implements Graphics {
3538
3639 private LightGizmoRenderer lightGizmoRenderer ;
3740
41+ public static int faceCount = 0 ;
42+
43+ public static int vertexCount = 0 ;
44+
3845 @ Override
3946 public void setAmbientColor (math .Color ambientColor ) {
4047 this .ambientColor = ambientColor ;
@@ -66,6 +73,8 @@ public GraphicsPImpl(PApplet p) {
6673
6774 @ Override
6875 public void fillFaces (Mesh3D mesh ) {
76+ faceCount += mesh .faces .size ();
77+ vertexCount += mesh .vertices .size ();
6978 if (wireframeMode ) {
7079 g .noFill ();
7180 stroke ();
@@ -342,9 +351,9 @@ public void rotateZ(float angle) {
342351
343352 @ Override
344353 public void rotate (float rx , float ry , float rz ) {
345- g .rotateX (rx );
346- g .rotateY (ry );
347- g .rotateZ (rz );
354+ g .rotateX (rx );
355+ g .rotateY (ry );
356+ g .rotateZ (rz );
348357 }
349358
350359 public void camera () {
@@ -460,15 +469,48 @@ public void applyCamera(Camera camera) {
460469 if (camera == null ) {
461470 throw new IllegalArgumentException ("Camera instance cannot be null." );
462471 }
463-
472+
473+ // g.resetMatrix();
474+ // Matrix4f m = camera.getViewProjectionMatrix();
475+ //
476+ //
477+ // Vector3f target = camera.getTarget();
478+ // Vector3f eye = camera.getTransform().getPosition();
479+ // Matrix4f look = Matrix4f.lookAt(eye, target, new Vector3f(0, 1, 0));
480+ //
481+ // m = m.multiply(look);
482+
483+ // g.getMatrix().set(m.getValues());
484+
464485 float fov = camera .getFieldOfView ();
465486 float aspect = camera .getAspectRatio ();
466487 float near = camera .getNearPlane ();
467488 float far = camera .getFarPlane ();
468- g .perspective (fov , aspect , near , far );
489+ // g.perspective(fov, aspect, near, far);
490+
491+ Matrix4f m = camera .getProjectionMatrix ();
492+ ((PGraphicsOpenGL ) g ).projection .set (m .getValues ());
469493
470494 Vector3f target = camera .getTarget ();
471495 Vector3f eye = camera .getTransform ().getPosition ();
472496 g .camera (eye .x , eye .y , eye .z , target .x , target .y , target .z , 0 , 1 , 0 );
473497 }
498+
499+ @ Override
500+ public void drawImage (Image image , float x , float y ) {
501+ if (image .getBackendImage () instanceof PImage ) {
502+ g .image ((PImage ) image .getBackendImage (), x , y );
503+ } else {
504+ throw new IllegalArgumentException ("Unsupported image backend." );
505+ }
506+ }
507+
508+ @ Override
509+ public void drawImage (Image image , float x , float y , float width , float height ) {
510+ if (image .getBackendImage () instanceof PImage ) {
511+ g .image ((PImage ) image .getBackendImage (), x , y , width , height );
512+ } else {
513+ throw new IllegalArgumentException ("Unsupported image backend." );
514+ }
515+ }
474516}
0 commit comments