Skip to content

Commit

Permalink
Refactoring main activity, moving on to more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rj committed Feb 20, 2011
1 parent d5f5c0d commit 306298c
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 250 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
default.properties
bin
gen
res
Expand Down
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rj.processing" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<application android:label="MSAPong" android:icon="@drawable/icon">
<activity android:name=".MSAPong"
<activity android:name="PlasmaPong"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
2 changes: 1 addition & 1 deletion default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# project structure.

# Project target.
target=android-7
target=android-8
Binary file removed libs/opengl.jar
Binary file not shown.
Binary file removed libs/processing-coreold.jar
Binary file not shown.
245 changes: 0 additions & 245 deletions src/com/rj/processing/MSAPong.java

This file was deleted.

121 changes: 121 additions & 0 deletions src/com/rj/processing/PlasmaFluid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.rj.processing;

import msafluid.MSAFluidSolver2D;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PImage;
import android.util.DisplayMetrics;
import android.view.MotionEvent;

import com.rj.processing.mt.MTCallback;
import com.rj.processing.mt.MTManager;
import com.rj.processing.pong.Ball;
import com.rj.processing.pong.Game;

public class PlasmaFluid {
PApplet p;

final float FLUID_WIDTH = 60;

public MSAFluidSolver2D fluidSolver;

PImage imgFluid;
boolean touchupdated = false;

public PlasmaFluid(PApplet p) {
this.p = p;
// create fluid and set options
fluidSolver = new MSAFluidSolver2D((int)(FLUID_WIDTH), (int)(FLUID_WIDTH * p.height/p.width));
setupFluid();

// create image to hold fluid picture
imgFluid = p.createImage(fluidSolver.getWidth(), fluidSolver.getHeight(), PApplet.RGB);

}

public void setupFluid() {
fluidSolver.enableRGB(true).setFadeSpeed(0.01f).setDeltaT(0.5f).setVisc(0.0001f).setSolverIterations(3);
//fluidSolver.enableRGB(true).setFadeSpeed(0.01f).setDeltaT(1).setVisc(1).setSolverIterations(5);
}



public void draw(PApplet p) {
p.colorMode(PApplet.RGB, 1);

fluidSolver.update();

imgFluid.loadPixels();
int cellcount = fluidSolver.getNumCells();
for(int i=0; i<cellcount; i++) { //optimize here.
imgFluid.pixels[i] = p.color(fluidSolver.r[i], fluidSolver.g[i], fluidSolver.b[i]);
}
imgFluid.updatePixels();// fastblur(imgFluid, 2);

p.image(imgFluid, 0, 0, p.width, p.height);

p.colorMode(PApplet.RGB, 255);

}


// add force and dye to fluid, and create particles
public void addForce(PApplet p, float x, float y, float dx, float dy) {
float colorMult = 5;
colorMult=colorMult*y;
float velocityMult = 30.0f;

if (dx > 1) dx = 1;
if (dy > 5) dy = 1;

int drawColor;

p.colorMode(PApplet.HSB, 360, 1, 1);
float hue = ((x + y) * 180 + p.frameCount) % 360;
if (x < 0.5f)
hue = 0;
else
hue = 180;
drawColor = p.color(hue, 1, 1);
p.colorMode(PApplet.RGB, 1);
for (int i=0; i<3; i++) {
for (int j=0; j<1; j++) {
int index = fluidSolver.getIndexForNormalizedPosition(x+.01f*i, y+.01f*j);
fluidSolver.rOld[index] += p.red(drawColor) * colorMult;
fluidSolver.gOld[index] += p.green(drawColor) * colorMult;
fluidSolver.bOld[index] += p.blue(drawColor) * colorMult;

fluidSolver.uOld[index] += dx * velocityMult;
fluidSolver.vOld[index] += dy * velocityMult;
}
}
//experimental code. interpolate between points.
//convert back to normal
// x = x * width;
// y = y * height;
// dx = dx * width/30f * 1000f/this.frameRate; //the 30 is a hack because this was usuallly called with dx * 30
// dy = dy * height/30f * 1000f/this.frameRate;
//
// float steps = (float)Math.sqrt(dx * dx + dy * dy);
// float stepX = dx/steps;
// float stepY = dy/steps;
//
// float vx = x-dx;
// float vy = y-dy;
// for (float i=0; i < steps; i += 1f ) {
// vx += stepX;
// vy += stepY;
// int index = fluidSolver.getIndexForNormalizedPosition(vx/width, vy/height);
// fluidSolver.rOld[index] += red(drawColor) * colorMult;
// fluidSolver.gOld[index] += green(drawColor) * colorMult;
// fluidSolver.bOld[index] += blue(drawColor) * colorMult;
//
// fluidSolver.uOld[index] += dx/width * 1f;
// fluidSolver.vOld[index] += dy/height * 1f;
// }

}



}
Loading

0 comments on commit 306298c

Please sign in to comment.