/** Company: Shout3D LLC Project: Shout3D 2.0 Sample Code Class: InvertSceneEffect Date: March 23, 2000 Description: A simple example of a PostRenderEffect that makes the scene have an animated waviness run through it. (C) Copyright Shout3D LLC. - 1997-2001 - All rights reserved */ package custom_nodes; import shout3d.core.*; import shout3d.*; import java.awt.Graphics; /** * InvertSceneEffect * * @author Dave Westwood */ public class WavySceneEffect extends PostRenderEffect { // Amplitude of the wave in pixels final public IntField waveAmplitude = new IntField(this, "waveAmplitude", Field.ANY, 30); // Length of the wave in pixels final public IntField waveLength = new IntField(this, "waveLength", Field.ANY, 60); // Velocity of animation of the wave, in pixels per second. final public IntField crawlVelocity = new IntField(this, "crawlVelocity", Field.ANY, 10); /** * Constructs a default InvertSceneEffect node. */ public WavySceneEffect() {} int[] horizOffset = null; double startClockT = -1; int oldAmplitude = -1; int oldWavelength = -1; int rowShift, toPixel, rowFirst, rowLast; public void filter(Graphics offScreenGraphics, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight) { if (surface_pixel_bits == null) return; // Store these to avoid any nastiness happening from field values that change // while we are filtering. int curWaveAmplitude = waveAmplitude.getValue(); int curWaveLength = waveLength.getValue(); int curCrawlVelocity = crawlVelocity.getValue(); // Allocate an array of horizontal offsets for each of the rows within a waveLength's cycle if (horizOffset == null || oldAmplitude != curWaveAmplitude || oldWavelength != curWaveLength) { horizOffset = new int[curWaveLength]; for (int i = 0; i < curWaveLength; i++) { horizOffset[i] = (int) (curWaveAmplitude * Math.sin( 2 * 3.14159 * ((float)i) / curWaveLength)); } oldAmplitude = curWaveAmplitude; oldWavelength = curWaveLength; } // How much time has passed since beginning? Need this for crawl which is // velocity based. if (startClockT == -1) { startClockT = getViewer().getClock().getAbsoluteTime(); } double deltaT = getViewer().getClock().getAbsoluteTime() - startClockT; toPixel = 0; for (int row=0; row 0) { for (int col=0; col= 0; col--) { if (col + rowShift >= 0){ surface_pixel_bits[toPixel] = surface_pixel_bits[toPixel+rowShift]; } else { surface_pixel_bits[toPixel] = surface_pixel_bits[rowFirst]; } toPixel--; } toPixel += deviceWidth + 1; } else { // rowShift is 0, skip to next row. toPixel += deviceWidth; } } } }