How does waterProcessor..setPlane(..) work?

Hi there,

I’ve recently started into JMonkeyEngine after being with LibGdx for a while, reading the book JMonkey, a Practical Guide. Throughout the book, there were some concepts that I didn’t fully understand(mostly mathematical) but I dismissed it as I didn’t necessarily need to know how something worked to use it. However, now that I’m learning about terrain I am very confused on how the code below works:

waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y,;

The book’s explanation is incredibly short and all I know right now is that I’m somehow giving a constant and a normal or so(I have no idea what that is). Am I even expected to know what this does, or simply write it every time? Apologies if this is in the wrong section. I’ve read the JavaDoc for it and it said it took in a normal and a constant, I am confused about what those are and what they have to do with water reflection. With other terms, I had a somewhat vauge understanding, but I have little idea about what this means. If anyone could point me in the right direction, or if I even need to know why that works, many thanks.

3-D graphics is going to be difficult if you haven’t studied analytic geometry.

A plane can be described by an equation of the form a * x + b * y + c * z = k.

A plane’s “normal” is a 3-D vector that points 90 degrees from the the surface of the plane in all directions. For the plane described above, the vector (a, b, c) would be a normal. For a horizontal plane in Y-up coordinates, the normal is usually (0, 1, 0), known in JMonkeyEngine as UNIT_Y.

A plane’s “constant” is the “k” in the equation above. For a horizontal plane in Y-up coordinates, the constant is simply the Y coordinate of all its points.

So as long as you use Y-up coordinates and your reflecting surface is horizontal, the plane you’ll want will be new Plane(Vector3f.UNIT_Y, planeY) where planeY is the Y coordinate of all points in the plane.

The dot function is a more general way of calculating what the constant should be, to handle cases where normal isn’t (0, 1, 0).

I hope that helps.


Thank you very much for the quick reply!

Yes, unfortunately I have not taken any analytic geometry. Your explanation has helped quite a bit, although I am still unsure as to how the dot product works(could I just specify 0 at all times?) so I am looking further into that. Is it important to know these concepts in order to create polished 3d game? Or can I go without fully understanding the geometry behind these concepts?

1 Like

This might help:

The dot product of two vectors is the cosine of the angle between them. A simple way of describing one of the most magic and useful things in 3D math.

1 Like

Thank you, I will take a look at that. These dummies guides seem to be very helpful to me :stuck_out_tongue:

Without analytic geometry, your ability to create games with JMonkeyEngine is going to be very limited, I think.

Ah. I guess I’ll research analytic geometry, then, when I come across something that I can’t do. Thanks!

1 Like

I am not sure if I missed it but it seems the dummies guide does include anything regarding dot product. It was still helpful, though.

EDIT: Also, sorry if I am mistaken, but if I recall from geometry doesn’t cos(theta) retrieve the x value of the vector, and sin(theta) the y value, from the unit circle?

Yeah, but that doesn’t have anything to do with what I said.

Ooh okay…, sorry I misread that… Thanks, it generally makes more sense… so just need to remember that always use dot product for planeY(maybe in future when I go to college ect/calc I will learn true meaning behind it) and what the “up” axis is(which is almost always y, right?)

One of the forms of defining a plane is normal + distance from origin. (Really if you pick up literally any graphics book this will be in the first or second chapter. Highly recommend reading some background material on these subjects.)

Any easy way to find the distance from origin is to do a dot product of the plane’s normal with any point on that plane… because the cosine of the angle between the normal and the vector from origin->point on plane will the distance from origin along the plane normal.

Draw a picture. You’ll see.

Edit: an important point I guess is that the dot product of two vectors is the cosine of the angle between them multiplied by the length of both vectors. If one of the vectors is length one and the other isn’t… you get a nice projection along the normalized vector.

Edit 2: one day you might see that the dot product is actually the fundamental component of 90% of computer graphics. Matrix transform multiplication? Just a bunch of dot products… and so on.

Oh!! Thanks so much, I completely understand that now… ! The cosine of the angle of the perpendicular line(normal) and the diagonal line from origin to the origin of plane, is equal tot he distance from start of perpendicular line (origin) to the middle of plane… I am a bit confused on why that is called “plane y” then, since it is the offset of middle of plane.

Not sure where you got “plane y”… so I can’t comment. The javadoc for plane calls it “normal” and “constant”… which is a funny name, too, but at least not inaccurate.

Hmm okay, I thought I saw sgold user say that, maybe it was a misunderstanding, I guess.

So as long as you use Y-up coordinates and your reflecting surface is horizontal, the plane you’ll want will be new Plane(Vector3f.UNIT_Y, planeY) where planeY is the Y coordinate of all points in the plane.

I‘ve found that having a strong grasp of basic vector math (addition/subtraction, dot products, cross products, normalization, and how those are used) is incredibly useful. Other topics in analytic geometry, like the plane equations, matrix multiplication, and transform matrices, are also very useful, but there’s enough library code for things like that in jME that 90% of the time you don’t need to worry about the details (but familiarity with the concepts is still useful).

Of course, the more analytic geometry you learn and master the better, but you can easily start with nothing but the basics and move on to more advanced topics at your own pace.

1 Like

I could learn what was just said here but it makes my head hurt.

I think its just easier to run code and experiment with it.

If you are interested.

At the top of the forum under documentation is the wiki link. It is accurate up to version 3.2.4 of the engine.

1 Like