.. | .. |
---|
206 | 206 | |
---|
207 | 207 | SetCamera(cam); |
---|
208 | 208 | |
---|
209 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 209 | + // Warning: not used. |
---|
| 210 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
210 | 211 | |
---|
211 | 212 | object = o; |
---|
212 | 213 | |
---|
.. | .. |
---|
9699 | 9700 | |
---|
9700 | 9701 | if (renderCamera != lightCamera) |
---|
9701 | 9702 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9702 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9703 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9703 | 9704 | |
---|
9704 | 9705 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9705 | 9706 | |
---|
.. | .. |
---|
9715 | 9716 | |
---|
9716 | 9717 | if (renderCamera != lightCamera) |
---|
9717 | 9718 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9718 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9719 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9719 | 9720 | |
---|
9720 | 9721 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9721 | 9722 | |
---|
.. | .. |
---|
10916 | 10917 | // if (parentcam != renderCamera) // not a light |
---|
10917 | 10918 | if (cam != lightCamera) |
---|
10918 | 10919 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10919 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10920 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10920 | 10921 | |
---|
10921 | 10922 | for (int j = 0; j < 4; j++) |
---|
10922 | 10923 | { |
---|
.. | .. |
---|
10931 | 10932 | // if (parentcam != renderCamera) // not a light |
---|
10932 | 10933 | if (cam != lightCamera) |
---|
10933 | 10934 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10934 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10935 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10935 | 10936 | |
---|
10936 | 10937 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10937 | 10938 | |
---|
.. | .. |
---|
12402 | 12403 | String program = |
---|
12403 | 12404 | // Min shader |
---|
12404 | 12405 | "!!ARBfp1.0\n" + |
---|
12405 | | - "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" + |
---|
| 12406 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
12406 | 12407 | "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
12407 | 12408 | "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
12408 | 12409 | "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
12409 | 12410 | "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12411 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12412 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12413 | + "PARAM light2cam2 = program.env[12];" + |
---|
12410 | 12414 | "TEMP temp;" + |
---|
12411 | 12415 | "TEMP light;" + |
---|
12412 | 12416 | "TEMP ndotl;" + |
---|
12413 | 12417 | "TEMP normal;" + |
---|
12414 | 12418 | "TEMP depth;" + |
---|
| 12419 | + "TEMP eye;" + |
---|
| 12420 | + "TEMP pos;" + |
---|
12415 | 12421 | |
---|
12416 | 12422 | "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
12417 | | - |
---|
| 12423 | + Normalize("normal") + |
---|
12418 | 12424 | "MOV light, state.light[0].position;" + |
---|
12419 | 12425 | "DP3 ndotl.x, light, normal;" + |
---|
12420 | 12426 | |
---|
12421 | 12427 | // shadow |
---|
12422 | | - "MOV temp, fragment.texcoord[1];" + |
---|
12423 | | - TextureFetch("depth", "temp", "1") + |
---|
| 12428 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12429 | + "MOV temp, pos;" + |
---|
| 12430 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
12424 | 12431 | //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
12425 | | - "SLT temp.x, fragment.texcoord[1].z, depth.z;" + |
---|
12426 | | - |
---|
| 12432 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
12427 | 12433 | |
---|
12428 | 12434 | // No shadow when out of frustum |
---|
12429 | 12435 | //"SGE temp.y, depth.z, zero123.y;" + |
---|
12430 | 12436 | //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
12431 | 12437 | |
---|
12432 | | - "MUL ndotl.x, ndotl.x, temp.x;" + |
---|
12433 | | - "MAX ndotl.x, ndotl.x, pow2.y;" + |
---|
| 12438 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
12434 | 12439 | |
---|
| 12440 | + // Backlit |
---|
| 12441 | + "MOV pos.w, zero123.y;" + |
---|
| 12442 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12443 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12444 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12445 | + Normalize("eye") + |
---|
| 12446 | + |
---|
| 12447 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12448 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12449 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12450 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12451 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12452 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12453 | + |
---|
| 12454 | + "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12455 | + |
---|
| 12456 | + // Pigment |
---|
12435 | 12457 | "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12436 | 12458 | "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
12437 | 12459 | "MUL temp, temp, ndotl.x;" + |
---|
12438 | 12460 | |
---|
12439 | 12461 | "MUL temp, temp, zero123.z;" + |
---|
12440 | 12462 | |
---|
12441 | | - "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12463 | + //"MUL temp, temp, ndotl.y;" + |
---|
12442 | 12464 | |
---|
| 12465 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
12443 | 12466 | "MOV result.color, temp;" + |
---|
12444 | 12467 | "END"; |
---|
12445 | 12468 | |
---|
.. | .. |
---|
12581 | 12604 | "MUL temp, floor, mapgrid.x;" + |
---|
12582 | 12605 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12583 | 12606 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12584 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12607 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12585 | 12608 | "") + |
---|
12586 | 12609 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12587 | 12610 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12588 | 12611 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12589 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12612 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12590 | 12613 | "") + |
---|
12591 | 12614 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12592 | 12615 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12593 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12616 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12594 | 12617 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12595 | 12618 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12596 | 12619 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12597 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12620 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12598 | 12621 | "") + |
---|
12599 | 12622 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12600 | 12623 | //"MOV params, material;" + |
---|
.. | .. |
---|
13392 | 13415 | return out; |
---|
13393 | 13416 | } |
---|
13394 | 13417 | |
---|
13395 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13418 | + // Also does frustum culling |
---|
| 13419 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13396 | 13420 | { |
---|
13397 | 13421 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13398 | 13422 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
.. | .. |
---|
14255 | 14279 | drag = false; |
---|
14256 | 14280 | //System.out.println("Mouse DOWN"); |
---|
14257 | 14281 | editObj = false; |
---|
14258 | | - ClickInfo info = new ClickInfo(); |
---|
14259 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14260 | | - info.pane = this; |
---|
14261 | | - info.camera = renderCamera; |
---|
14262 | | - info.x = x; |
---|
14263 | | - info.y = y; |
---|
14264 | | - info.modifiers = modifiersex; |
---|
14265 | | - editObj = object.doEditClick(info, 0); |
---|
| 14282 | + //ClickInfo info = new ClickInfo(); |
---|
| 14283 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14284 | + object.clickInfo.pane = this; |
---|
| 14285 | + object.clickInfo.camera = renderCamera; |
---|
| 14286 | + object.clickInfo.x = x; |
---|
| 14287 | + object.clickInfo.y = y; |
---|
| 14288 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14289 | + editObj = object.doEditClick(//info, |
---|
| 14290 | + 0); |
---|
14266 | 14291 | if (!editObj) |
---|
14267 | 14292 | { |
---|
14268 | 14293 | hasMarquee = true; |
---|
.. | .. |
---|
14662 | 14687 | if (editObj) |
---|
14663 | 14688 | { |
---|
14664 | 14689 | drag = true; |
---|
14665 | | - ClickInfo info = new ClickInfo(); |
---|
14666 | | - info.bounds.setBounds(0, 0, |
---|
| 14690 | + //ClickInfo info = new ClickInfo(); |
---|
| 14691 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14667 | 14692 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14668 | | - info.pane = this; |
---|
14669 | | - info.camera = renderCamera; |
---|
14670 | | - info.x = x; |
---|
14671 | | - info.y = y; |
---|
14672 | | - object.GetWindow().copy |
---|
14673 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14693 | + object.clickInfo.pane = this; |
---|
| 14694 | + object.clickInfo.camera = renderCamera; |
---|
| 14695 | + object.clickInfo.x = x; |
---|
| 14696 | + object.clickInfo.y = y; |
---|
| 14697 | + object //.GetWindow().copy |
---|
| 14698 | + .doEditDrag(//info, |
---|
| 14699 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14674 | 14700 | } else |
---|
14675 | 14701 | { |
---|
14676 | 14702 | if (x < startX) |
---|
.. | .. |
---|
14819 | 14845 | } |
---|
14820 | 14846 | } |
---|
14821 | 14847 | |
---|
| 14848 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14849 | + |
---|
14822 | 14850 | public void mouseMoved(MouseEvent e) |
---|
14823 | 14851 | { |
---|
14824 | 14852 | //System.out.println("mouseMoved: " + e); |
---|
14825 | 14853 | if (isRenderer) |
---|
14826 | 14854 | return; |
---|
14827 | 14855 | |
---|
14828 | | - ClickInfo ci = new ClickInfo(); |
---|
14829 | | - ci.x = e.getX(); |
---|
14830 | | - ci.y = e.getY(); |
---|
14831 | | - ci.modifiers = e.getModifiersEx(); |
---|
14832 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14833 | | - ci.pane = this; |
---|
14834 | | - ci.camera = renderCamera; |
---|
| 14856 | + // Mouse cursor feedback |
---|
| 14857 | + object.clickInfo.x = e.getX(); |
---|
| 14858 | + object.clickInfo.y = e.getY(); |
---|
| 14859 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14860 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14861 | + object.clickInfo.pane = this; |
---|
| 14862 | + object.clickInfo.camera = renderCamera; |
---|
14835 | 14863 | if (!isRenderer) |
---|
14836 | 14864 | { |
---|
14837 | 14865 | //ObjEditor editWindow = object.editWindow; |
---|
14838 | 14866 | //Object3D copy = editWindow.copy; |
---|
14839 | | - if (object.doEditClick(ci, 0)) |
---|
| 14867 | + if (object.doEditClick(//clickInfo, |
---|
| 14868 | + 0)) |
---|
14840 | 14869 | { |
---|
14841 | 14870 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14842 | 14871 | } else |
---|
.. | .. |
---|
15862 | 15891 | |
---|
15863 | 15892 | int width = getBounds().width; |
---|
15864 | 15893 | int height = getBounds().height; |
---|
15865 | | - ClickInfo info = new ClickInfo(); |
---|
15866 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15867 | 15894 | //Image img = CreateImage(width, height); |
---|
15868 | 15895 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15869 | 15896 | |
---|
.. | .. |
---|
15940 | 15967 | } |
---|
15941 | 15968 | if (object != null && !hasMarquee) |
---|
15942 | 15969 | { |
---|
| 15970 | + if (object.clickInfo == null) |
---|
| 15971 | + object.clickInfo = new ClickInfo(); |
---|
| 15972 | + ClickInfo info = object.clickInfo; |
---|
| 15973 | + //ClickInfo info = new ClickInfo(); |
---|
| 15974 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 15975 | + |
---|
15943 | 15976 | if (isRenderer) |
---|
15944 | 15977 | { |
---|
15945 | | - info.flags++; |
---|
| 15978 | + object.clickInfo.flags++; |
---|
15946 | 15979 | double frameAspect = (double) width / (double) height; |
---|
15947 | 15980 | if (frameAspect > renderCamera.aspect) |
---|
15948 | 15981 | { |
---|
15949 | 15982 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15950 | | - info.bounds.width -= width - desired; |
---|
15951 | | - info.bounds.x += (width - desired) / 2; |
---|
| 15983 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 15984 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15952 | 15985 | } else |
---|
15953 | 15986 | { |
---|
15954 | 15987 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15955 | | - info.bounds.height -= height - desired; |
---|
15956 | | - info.bounds.y += (height - desired) / 2; |
---|
| 15988 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 15989 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15957 | 15990 | } |
---|
15958 | 15991 | } |
---|
15959 | 15992 | |
---|
15960 | | - info.g = gr; |
---|
15961 | | - info.camera = renderCamera; |
---|
| 15993 | + object.clickInfo.g = gr; |
---|
| 15994 | + object.clickInfo.camera = renderCamera; |
---|
15962 | 15995 | /* |
---|
15963 | 15996 | // Memory intensive (brep.verticescopy) |
---|
15964 | 15997 | if (!(object instanceof Composite)) |
---|
15965 | 15998 | object.draw(info, 0, false); // SLOW : |
---|
15966 | 15999 | */ |
---|
15967 | | - if (!isRenderer) |
---|
| 16000 | + if (!isRenderer) // && drag) |
---|
15968 | 16001 | { |
---|
15969 | 16002 | Grafreed.Assert(object != null); |
---|
15970 | 16003 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15972 | 16005 | { |
---|
15973 | 16006 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15974 | 16007 | |
---|
15975 | | - info.DX = 0; |
---|
15976 | | - info.DY = 0; |
---|
15977 | | - info.W = 1; |
---|
| 16008 | + object.clickInfo.DX = 0; |
---|
| 16009 | + object.clickInfo.DY = 0; |
---|
| 16010 | + object.clickInfo.W = 1; |
---|
15978 | 16011 | if (hitSomething == Object3D.hitCenter) |
---|
15979 | 16012 | { |
---|
15980 | 16013 | info.DX = X; |
---|
.. | .. |
---|
15986 | 16019 | info.DY -= info.bounds.height/2; |
---|
15987 | 16020 | } |
---|
15988 | 16021 | |
---|
15989 | | - object.drawEditHandles(info, 0); |
---|
| 16022 | + object.drawEditHandles(//info, |
---|
| 16023 | + 0); |
---|
15990 | 16024 | |
---|
15991 | 16025 | if (drag && (X != 0 || Y != 0)) |
---|
15992 | 16026 | { |
---|
.. | .. |
---|
15999 | 16033 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
16000 | 16034 | break; |
---|
16001 | 16035 | case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
16002 | | - gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
| 16036 | + gr.drawLine(X, Y, 0, 0); |
---|
16003 | 16037 | break; |
---|
16004 | 16038 | } |
---|
16005 | 16039 | |
---|