package net.anzix.fsz.sceneComponents;
import com.ardor3d.extension.effect.water.ProjectedGrid;
import com.ardor3d.extension.effect.water.WaterHeightGenerator;
import com.ardor3d.extension.effect.water.WaterNode;
import com.ardor3d.math.Plane;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.Camera;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.extension.Skybox;
import com.ardor3d.scenegraph.shape.Quad;
import com.ardor3d.util.ReadOnlyTimer;
import com.ardor3d.util.Timer;
/**
*
* @author elcsiga
*/
public class Water extends WaterNode{
private Quad waterQuad;
//float quadHalfSize;
float waterHeight;
private final double textureScale = 0.05;
private ProjectedGrid projectedGrid;
public Water(Camera camera, Node reflectedNode, Skybox skybox, float farPlane, float waterHeight, Timer timer ) {
super(camera, 4, true, true) ;
// Create a new WaterNode with refraction enabled.
setClipBias(0.5f);
setWaterMaxAmplitude(5.0f);
// Setup textures to use for the water.
setNormalMapTextureString("images/water/normalmap3.dds");
setDudvMapTextureString("images/water/dudvmap.png");
setFallbackMapTextureString("images/water/water2.png");
setFoamMapTextureString("images/water/oceanfoam.png");
this.waterHeight = waterHeight;
setWaterPlane(new Plane(new Vector3(0.0, 1.0, 0.0), waterHeight));
useFadeToFogColor(true);
projectedGrid = new ProjectedGrid("ProjectedGrid", camera, 100, 70, 0.01f, new FszWaterHeightGenerator(waterHeight), timer);
projectedGrid.setNrUpdateThreads(Runtime.getRuntime().availableProcessors());
attachChild(projectedGrid);
addReflectedScene(reflectedNode);
setSkybox(skybox);
//quadHalfSize = farPlane;
}
public void update(final ReadOnlyTimer timer, Camera camera ) {
update(timer.getTimePerFrame());
}
/*rivate void setVertexCoords(final float x, final float y, final float z) {
final FloatBuffer vertBuf = waterQuad.getMeshData().getVertexBuffer();
vertBuf.clear();
vertBuf.put(x - quadHalfSize).put(y).put(z - quadHalfSize);
vertBuf.put(x - quadHalfSize).put(y).put(z + quadHalfSize);
vertBuf.put(x + quadHalfSize).put(y).put(z + quadHalfSize);
vertBuf.put(x + quadHalfSize).put(y).put(z - quadHalfSize);
}*/
/*private void setTextureCoords(final int buffer, double x, double y, double textureScale) {
x *= textureScale * 0.5f;
y *= textureScale * 0.5f;
textureScale = quadHalfSize * textureScale;
FloatBuffer texBuf;
texBuf = waterQuad.getMeshData().getTextureBuffer(buffer);
texBuf.clear();
texBuf.put((float) x).put((float) (textureScale + y));
texBuf.put((float) x).put((float) y);
texBuf.put((float) (textureScale + x)).put((float) y);
texBuf.put((float) (textureScale + x)).put((float) (textureScale + y));
}*/
}