Sombrero's function

I know what is happening, THE thing is, that I need numbers something like

cam.getAxisX();
cam.getAxisY(); 

while I will click just to put in to variables tileX and tileY

waveMap[currmap][tileX][tileY] = 10f;

I know what is happening I just need to get the numbers :smiley: Because atm. I have randoms in tileX and TileY :smile:

If you have a proper direction vector then the collision results should give you all that you need. You don’t need your getAxisX() or getAxisY() methods (though camera has them they are just called something different and I will make you find the javadoc to know because it will help you in the future to know where the javadoc is).

tileX and tileY are a function of the collision point and the size of your quad.

well yeah, but there is a problem that waveMap requried type of variables int and CollisionResults is collisionResults, that’s why I can’t put CollisionResults into tileX and tileY :confused:

I can’t tell if you are joking are not… You know that CollisionResults is a container with CollisionResult objects in it, right? And those have things like collision location and stuff?

If you aren’t joking then you need to go and do the tutorials, I think.

Just a bit :smiley: Sorry for this kind of joke :smiley:

Ray ray = new Ray(cam.getLocation(), cam.getDirection());
CollisionResults results = new CollisionResults();
map.collideWith(ray, results);
for (int i = 0; i < results.size(); i++) {
      float tileX = results.getCollision(i).getContactPoint().getX();
      float tileY = results.getCollision(i).getContactPoint().getY();

if (results.size() > 0) {
      waveMap[currmap][(int) tileX][(int) tileY] = 10f; //<= setting deepness
      }
} 

Should be like this right? :smile:

But it still doesn’t make any ripples. Well, this is endless.

Nope. Again, I suggest you run in a debugger and see what values you are getting or add some System.out.println() calls to see what the values are. You will be forever lost unless you actually start looking into stuff and seeing how its working.

I’ll have to agree with @pspeed here about the println() and the debugger. Whenever I write code, I put in as many println()s as I can to see exactly what is happening. In fact, that function helped me find a coding mistake last week, I mixed up my x and y coordinates parsing through image data. They put that function there for a reason, I highly suggest you use it.

Scattering println’s throughout your code is gross man, don’t do that - learn to use the debugger, you’ll be better off.

Disclaimer: I use println’s ALL THE TIME because I am too lazy to get better at using the debugger

I did it quite more

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.collision.CollisionResults;
import com.jme3.font.BitmapText;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.VertexBuffer;
import com.jme3.util.SkyFactory;

public class Main extends SimpleApplication {

    private Node map;
//Vertices of loaded water patch
    VertexBuffer vertices;
//Wave map constants to control waves
    int currmap = 0;
    int nextmap = 1;
//Value of ripple (lenght)
    float waterDampen = 6.0f;
//Our water plane tiles number along X and Y axes
    int numTilesX = 100;
    int numTilesY = 100;
//Number of vertices along individual axes
    int numVertsX = numTilesX + 1;
    int numVertsY = numTilesY + 1;
    int vertindex = 0;
//Water wave map, deformation update will happen as well as waves propagation
    float[][][] waveMap = new float[2][numVertsX + 2][numVertsY + 2];
//Light
    private DirectionalLight dl = new DirectionalLight();
    private AmbientLight am = new AmbientLight();

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        createSky();
        createWaterSurface();
        createLight();
        initCrossHairs();
        initKeys();
        cam.setLocation(new Vector3f(8.12541789f, 7.218303f, 24.560389f));
    }

    private void createSky() {
        rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    }

    private void createWaterSurface() {
        map = (Node) assetManager.loadModel("Scenes/wate_glass.j3o");
        vertices = ((Geometry) map.getChild("Plane1")).getMesh().getBuffer(VertexBuffer.Type.Position);
        map.setLocalTranslation(new Vector3f(8, 0, 8));
        rootNode.attachChild(map);
    }

    private void createLight() {
        dl.setColor(ColorRGBA.White.clone().multLocal(2));
        dl.setDirection(new Vector3f(-1, -1, -1).normalize());
        rootNode.addLight(dl);
        am.setColor(ColorRGBA.White.mult(2));
        rootNode.addLight(am);
    }

    protected void initCrossHairs() {
        setDisplayStatView(false);
        guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
        BitmapText ch = new BitmapText(guiFont, false);
        ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
        ch.setText("+");
        ch.setLocalTranslation(settings.getWidth() / 2 - ch.getLineWidth() / 2,
                settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
        guiNode.attachChild(ch);
    }

    private void initKeys() {
        inputManager.addMapping("Shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        inputManager.addListener(actionListener, "Shoot");
    }
    private ActionListener actionListener = new ActionListener() {
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("Shoot") && !keyPressed) {
                Ray ray = new Ray(cam.getLocation(), cam.getDirection());
                CollisionResults results = new CollisionResults();
                map.collideWith(ray, results);
                for (int i = 0; i < results.size(); i++) {
                    float coordinateX = results.getCollision(i).getContactPoint().getX();
                    float coordinateY = results.getCollision(i).getContactPoint().getZ();
                    System.out.println("Coordinate X is: " + coordinateX);
                    System.out.println("Coordinate Y is: " + coordinateY);
                    float cooTileX = coordinateX / 0.16f + 1;
                    float cooTileY = coordinateY / 0.16f + 1;
                    System.out.println("Tile X is: " + cooTileX);
                    System.out.println("Tile Y is: " + cooTileY);
                    int tileX = Math.round(cooTileX);
                    int tileY = Math.round(cooTileY);
                    System.out.println("Vertice X is: " + tileX);
                    System.out.println("Vertice Y is: " + tileY);
                    waveMap[currmap][tileX][tileY] = 10f; //<= setting deepness
                }
            }
        }
    };

    @Override
    public void simpleUpdate(float tpf) {
        for (int countY = 1; countY < numVertsY + 1; countY++) {
            for (int countX = 1; countX < numVertsX + 1; countX++) {
                //calculate wave intensity for this point
                float n = waveMap[currmap][countX - 1][countY] + waveMap[currmap][countX + 1][countY]
                        + waveMap[currmap][countX][countY - 1] + waveMap[currmap][countX][countY + 1];
                n = (n / 2) - waveMap[nextmap][countX][countY];

                //dampen
                n = n - (n / waterDampen);

                waveMap[nextmap][countX][countY] = n;

                //set Point Height
                vertindex = ((countY - 1) * numVertsX) + countX;

                //set height of corresponding vertex trough vertex buffer
                vertices.setElementComponent(vertindex, 1, n);
            }
        }
        //swap the wave maps
        currmap = (currmap + 1) % 2;
        nextmap = (nextmap + 1) % 2;
    }
}

Well it does everything, says coordinates and says from which vector from blender scene water ripples start but it doen’s make these ripples. Sad story. :smiley:

I don’t know where is problem, because everything counts corectly.

I’ve been programming in Java for almost 20 years and I’ve used a Java debugger maybe five times (and of those, only three times was it helpful). %50+ of the time, I spot the bug as I’m putting in the println to verify anyway. Meanwhile, I’ve also gotten really good at spotting bugs and can often spot another coder’s bug while they are waiting for the debugger to load.

You will find that this is a religious issue near vi vs emacs. I have some pretty strong opinions on the subject.

In C/C++ the debugger was crucial because it was the only way to interpret core dumps. In Java, we get nice stack traces.

To me, logging is the absolute best. You have to think about what you are doing and what you will want to see and it can live as long as your app… turned on/off via config file or even at runtime.

System.out.println’s are the lazy/poor man’s logging when you “just want to see this right now”. I use them all the time in personal projects… less often in work projects… I try to never in my open source projects (if it was interesting to me then it might be interesting to you too).

Especially, in graphics and server applications (my two most developed areas), the debugger often as not prevents the bug from happening, anyway. And I’ve seen an over-reliance on a debugger completely dull a developer’s ability to actually read their own code.

them: “I’ll just run it in the debugger…”
me: “But you are obviously incrementing i instead of j right there…”
them: “But just let me see it run… Oh, yeah, look, j doesn’t have the right value.”
me: sigh…

If you find yourself using the debugger to spot your typos you are a full on addict. :slight_smile:

…assuming currmap is also what is expected, I’m getting you are saying that tileX and tileY as proper values? Or?

In the posted code, what is the issue you are seeing now?

Well you have me beat by 5 years in length of time programming, and perhaps I have inadvertently learned how to do it “right”. I’ve found a debugger - especially the step through stuff - invaluable for functional languages like javascript, but I’ve never really gotten to grips with using it in java for some reason.

Obviously, vi wins hands down. I don’t need an OS inside my editor…

:slight_smile: That was just Java. 1997 or so was my first “real” Java project. Pretty cool Swing-based microwave/cellular network planning tool. I did C professionally since 1991 or something and off and on even during the Java years.

Yes, some languages are better suited for a debugger… especially when the console is not consistent or convenient or logging is otherwise difficult to be useful (such as functional languages).

Still, I don’t know how many times I’ve been saved by seeing the logs of a system I hadn’t touched the code on in years but I’m still able to read and see what’s going wrong.

That is my major complaint with windows - the logs are obtuse, too verbose and not verbose enough at the same time, and hidden away in a dumb application. Try diagnosing what is delaying login or what is waking the computer from sleep at random times. Its a nightmare. Even when your own software uses plain text files for logs, the bloody file system works against you - locking in use files and other bollocks.

With unixes (even OSX) go to /var/log/ and done. Everything you could possibly need is in there.

Better yet, use something like “Byte Man” (http://byteman.jboss.org/) to inject logging without having any of that crap in the code.

Problem is everything is couting corectly, just it doesn’t show the ripples.

Well, I don’t see anywhere that you update the mesh.

Look at some of the other mesh examples that allow you to change them at runtime (like quad, etc.) to see how you can update a mesh buffer.

1 Like

Thx man, now I show something :slight_smile:

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.collision.CollisionResults;
import com.jme3.font.BitmapText;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.VertexBuffer;
import com.jme3.util.SkyFactory;
import java.nio.FloatBuffer;

public class Main extends SimpleApplication {

    private Node map;
//Vertices of loaded water patch
    VertexBuffer vertices;
    FloatBuffer fb;
    //Wave map constants to control waves
    int currmap = 0;
    int nextmap = 1;
//Value of ripple (lenght)
    float waterDampen = 6.0f;
//Our water plane tiles number along X and Y axes
    int numTilesX = 100;
    int numTilesY = 100;
//Number of vertices along individual axes
    int numVertsX = numTilesX + 1;
    int numVertsY = numTilesY + 1;
    int vertindex = 0;
//Water wave map, deformation update will happen as well as waves propagation
    float[][][] waveMap = new float[2][numVertsX + 2][numVertsY + 2];
//Light
    private DirectionalLight dl = new DirectionalLight();
    private AmbientLight am = new AmbientLight();

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        createSky();
        createWaterSurface();
        createLight();
        initCrossHairs();
        initKeys();
        cam.setLocation(new Vector3f(8.12541789f, 7.218303f, 24.560389f));
    }

    private void createSky() {
        rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    }

    private void createWaterSurface() {
        map = (Node) assetManager.loadModel("Scenes/wate_glass.j3o");
        vertices = ((Geometry) map.getChild("Plane1")).getMesh().getBuffer(VertexBuffer.Type.Position);
        fb = (FloatBuffer) vertices.getData();
        map.setLocalTranslation(new Vector3f(8, 0, 8));
        rootNode.attachChild(map);
    }

    private void createLight() {
        dl.setColor(ColorRGBA.White.clone().multLocal(2));
        dl.setDirection(new Vector3f(-1, -1, -1).normalize());
        rootNode.addLight(dl);
        am.setColor(ColorRGBA.White.mult(2));
        rootNode.addLight(am);
    }

    protected void initCrossHairs() {
        setDisplayStatView(false);
        guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
        BitmapText ch = new BitmapText(guiFont, false);
        ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
        ch.setText("+");
        ch.setLocalTranslation(settings.getWidth() / 2 - ch.getLineWidth() / 2,
                settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
        guiNode.attachChild(ch);
    }

    private void initKeys() {
        inputManager.addMapping("Shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        inputManager.addListener(actionListener, "Shoot");
    }
    private ActionListener actionListener = new ActionListener() {
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("Shoot") && !keyPressed) {
                Ray ray = new Ray(cam.getLocation(), cam.getDirection());
                CollisionResults results = new CollisionResults();
                map.collideWith(ray, results);
                for (int i = 0; i < results.size(); i++) {
                    float coordinateX = results.getCollision(i).getContactPoint().getX();
                    float coordinateY = results.getCollision(i).getContactPoint().getZ();
                    System.out.println("Coordinate X is: " + coordinateX);
                    System.out.println("Coordinate Y is: " + coordinateY);
                    float cooTileX = coordinateX / 0.16f + 1;
                    float cooTileY = coordinateY / 0.16f + 1;
                    System.out.println("Tile X is: " + cooTileX);
                    System.out.println("Tile Y is: " + cooTileY);
                    int tileX = Math.round(cooTileX);
                    int tileY = Math.round(cooTileY);
                    System.out.println("Vertice X is: " + tileX);
                    System.out.println("Vertice Y is: " + tileY);
                    waveMap[currmap][tileX][tileY] = 10f; //<= setting deepness
                }
            }
        }
    };

    @Override
    public void simpleUpdate(float tpf) {
        for (int countY = 1; countY < numVertsY + 1; countY++) {
            for (int countX = 1; countX < numVertsX + 1; countX++) {
                //calculate wave intensity for this point
                float n = waveMap[currmap][countX - 1][countY] + waveMap[currmap][countX + 1][countY]
                        + waveMap[currmap][countX][countY - 1] + waveMap[currmap][countX][countY + 1];
                n = (n / 2) - waveMap[nextmap][countX][countY];

                //dampen
                n = n - (n / waterDampen);

                waveMap[nextmap][countX][countY] = n;

                //set Point Height
                vertindex = ((countY - 1) * numVertsX) + countX;

                //set height of corresponding vertex trough vertex buffer
                vertices.setElementComponent(vertindex, 1, n);
            }
        }
        //swap the wave maps
        currmap = (currmap + 1) % 2;
        nextmap = (nextmap + 1) % 2;
        fb.rewind();
        vertices.updateData(fb);
    }
}

Now I have no clu, why it doesn’t start from the point of click, even I put in to wavemap proper data :confused: And what more, it makes 4 ripples in a line near each other.

that is what I was talking yesterday, it starts from 4 points at the same time and I do not know why. But It does what I wanted just I need to make it starts from one point (place) :smiley: