Permalink
Browse files

WIP

  • Loading branch information...
1 parent 767e04d commit ade488b81c6345cc0e82f2c5397e6dfbeb2dbd88 @toby1984 committed Jul 13, 2012
Showing with 24 additions and 7 deletions.
  1. +24 −7 src/main/java/de/codesourcery/engine/render/Panel3D.java
View
31 src/main/java/de/codesourcery/engine/render/Panel3D.java
@@ -25,10 +25,11 @@
private static final double PI = Math.PI;
private static final double PI_HALF = PI / 2.0d;
- private static boolean SHOW_NORMALS = true;
- private static boolean RENDER_WIREFRAME = true;
- private static boolean Z_SORTING_ENABLED = true;
- private static boolean RENDER_COORDINATE_SYSTEM = true;
+ private static final boolean SHOW_NORMALS = true;
+ private static final boolean RENDER_WIREFRAME = true;
+ private static final boolean Z_SORTING_ENABLED = true;
+ private static final boolean RENDER_COORDINATE_SYSTEM = true;
+ private static final boolean DRAW_VIEW_VECTOR = true;
private double scaleX = 100;
private double scaleY = 100;
@@ -200,6 +201,8 @@ public void render(Object3D obj , Graphics2D graphics) {
Vector4 p2 = modelMatrix.multiply( t.p2() );
Vector4 p3 = modelMatrix.multiply( t.p3() );
+ Vector4 p1Model = new Vector4( p1 );
+
p1 = viewMatrix.multiply( p1 );
p2 = viewMatrix.multiply( p2 );
p3 = viewMatrix.multiply( p3 );
@@ -214,6 +217,23 @@ public void render(Object3D obj , Graphics2D graphics) {
// the INVERTED modelView matrix
normal = normalMatrix.multiply( normal );
+ // calculate angle between surface normal and view vector
+ final double dotProduct= viewVector.dotProduct( normal );
+
+ if ( DRAW_VIEW_VECTOR ) {
+ graphics.setColor(Color.YELLOW );
+
+ Vector4 start = p1Model;
+ Vector4 viewNormalized = viewVector;
+ System.out.println("View: "+viewNormalized);
+// viewNormalized = modelMatrix.invert().multiply( viewMatrix.invert() ).multiply( projectionMatrix.invert() ).multiply( viewNormalized );
+// viewNormalized = modelMatrix.multiply(viewMatrix).multiptly( viewNormalized );
+ viewNormalized = viewNormalized.normalize().multiply( 100 );
+ Vector4 end = p1Model.plus( viewNormalized );
+ end = end.multiply( projectionMatrix.invert() );
+ drawLine( project( start , projectionMatrix ) , end , graphics );
+ }
+
if ( SHOW_NORMALS )
{
if ( ( count++ % 2 ) == 0 ) {
@@ -228,9 +248,6 @@ public void render(Object3D obj , Graphics2D graphics) {
}
- // calculate angle between surface normal and view vector
- double dotProduct= viewVector.dotProduct( normal );
-
if ( ! SHOW_NORMALS && dotProduct < 0.0 ) {
continue;
}

0 comments on commit ade488b

Please sign in to comment.