Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Where is the steapest axis on a plane?

ShkaboinkaShkaboinka Member Posts: 79
I have not really considered concepts of shading, lighting, etc. I have only just gotten to working with solid shapes in 3D (I use my own mechanics for this)...

To make some sorta effect, I thought maybe the color of things could change or get darker or something the further away it is in 3D space..
in Java there is a gradientPaint tool that will change the color or paint from colorOrPaintA to colorOrPaintB along the line described by pointA and pointB. So, I need to figure out where the steapest line (greates difference in z) on a polygon in 3D space is; The line must go from a point on one edge to a point on antoher (or from the corners, but that is not very likely).

Does anybody know how to find this line (make a routine that does this)?

Comments

  • chick80chick80 Member Posts: 349
    You won't manage to do much using a gradient, because the faces of a 3D object have not all the same orientation in space, so you should rotate, stretch and distort the gradient to use it correctly.
    The correct way of doing shading is to shade each pixel (costly) or to calculate the shading on the edges or on the vertices and then interpolate through them.
    Take a look at the Goraud algorithm, it's quite simple and gives good results.

    nICO

    [hr]
    [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


  • ShkaboinkaShkaboinka Member Posts: 79
    Well that might be useful when/if I ever learn to use something like OpenGL; But right now, I am just messing aroung with MY OWN 3D graphics routines using java. I don't have conrol over whatever pixels or whatever when a polygon is drawn; I just set the color or paint (the paint can be some kind of pattern, gradient, etc.), and then tell it to draw some polygon; All of the drawing routines are part of the jsdk, NOT something I can control... So, what I CAN do with these simple 2D graphics utilities and AWT is a gradient for depth or something, Okay?

    So back to the question: DOES ANYBODY KNOW HOW TO FIND THE STEEPEST SLOPE/LINE ACROSS A PLANE?
  • ShkaboinkaShkaboinka Member Posts: 79
    : Well that might be useful when/if I ever learn to use something like OpenGL; But right now, I am just messing aroung with MY OWN 3D graphics routines using java. I don't have conrol over whatever pixels or whatever when a polygon is drawn; I just set the color or paint (the paint can be some kind of pattern, gradient, etc.), and then tell it to draw some polygon; All of the drawing routines are part of the jsdk, NOT something I can control... So, what I CAN do with these simple 2D graphics utilities and AWT is a gradient for depth or something, Okay?
    :
    : So back to the question: DOES ANYBODY KNOW HOW TO FIND THE STEEPEST SLOPE/LINE ACROSS A PLANE?
    :
    Let me explain a little more:

    What I can do is find the line with the steepest slope, and do a gradient along that line in correlation to the Z or distance from "camera" from endpoint to endpoint
  • chick80chick80 Member Posts: 349
    : Well that might be useful when/if I ever learn to use something like OpenGL; But right now, I am just messing aroung with MY OWN 3D graphics routines using java. I don't have conrol over whatever pixels or whatever when a polygon is drawn; I just set the color or paint (the paint can be some kind of pattern, gradient, etc.), and then tell it to draw some polygon; All of the drawing routines are part of the jsdk, NOT something I can control... So, what I CAN do with these simple 2D graphics utilities and AWT is a gradient for depth or something, Okay?
    :
    Sorry, I did not understand well the problem...
    Ok, let's do a practical example on how you can do this:

    You have a situation like this:

    [code]
    ^ z
    | *P3
    |
    P1* | *P2
    |
    --------------T----------------> x
    |
    | L
    |
    C
    |
    [/code]
    C is the camera pos, T is the camera target, P1,P2,P3 the points of a triangle, L the light.

    Note that you should repeat this process for each triangle in your object (I assume you have objects formed of triangles).
    Stated that you can represent each point as a vector emerging from the
    origin, you can calculate the vectors L-P1, L-P2 and L-P3.

    Find the vector that has the lower module (in our example L-P2) and you know the gradient orientation (ie the L-P2 direction).
    Now you calculate the intersection beetween L-P2 and P1-P3 lines, that we call I (ok, my drawing sucks, but I cannot do something better ;-))

    [code]
    ^z
    |
    | I *P3
    |
    P1* | *P2
    |
    --------------T----------------> x
    |
    | L
    |
    C
    |
    [/code]

    So, if the object color was (in RGB) (100,100,100), you can define the color of P2 and I based on the distance from L.
    You should create a parameter that represent the maximum distance that the light can lit, suppose it's 500 units.
    So, if L-P2 is 100 and L-I is 110 you just do:
    1-(100/500) = 0.8
    1-(110/500) = 0.78

    So the gradient should be oriented on the P2-I direction and its colors should be the 80% and 78% of the object color (so, in our example 80,80,80 and 78,78,78).

    I hope this can help you. To have better shading you can always use a non linear approach when choosing the color (a quadratic or cubic approach is visually much more appealing but, as you're using Java, I think it would slow down too much the program).

    nICO

    [hr]
    [italic]How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.[/italic]
    JOHN KEATS


Sign In or Register to comment.