Project

General

Profile

« Previous | Next » 

Revision f046b159

Added by Leszek Koltunski almost 4 years ago

First attempt at the MeshBase.apply(VertexEffect) API.

View differences:

src/main/java/org/distorted/library/effect/VertexEffectSwirl.java
34 34
 */
35 35
public class VertexEffectSwirl extends VertexEffect
36 36
  {
37
  private static final EffectName NAME = EffectName.SWIRL;
38

  
37 39
  private Data1D mSwirl;
38 40
  private Data3D mCenter;
39 41
  private Data4D mRegion;
......
48 50
    {
49 51
    mCenter.get(uniforms,index+CENTER_OFFSET,currentDuration,step);
50 52
    mRegion.get(uniforms,index+REGION_OFFSET,currentDuration,step);
51
    boolean ret = mSwirl.get(uniforms,index,currentDuration,step);
53
    boolean ret = mSwirl.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
52 54

  
53
    uniforms[index] = (float)(Math.PI*uniforms[index]/180);
55
    uniforms[index+VALUES_OFFSET] = (float)(Math.PI*uniforms[index]/180);
54 56

  
55 57
    return ret;
56 58
    }
57 59

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59
// PUBLIC API
60 60
///////////////////////////////////////////////////////////////////////////////////////////////////
61 61
// Let d be the degree of the current vertex V with respect to center of the effect S and Region vRegion.
62 62
// This effect rotates the current vertex V by vInterpolated.x radians clockwise around the circle dilated
63 63
// by (1-d) around the center of the effect S.
64 64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
/**
66
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
67
 */
68
  public static void enable()
65

  
66
  static String code()
69 67
    {
70
    addEffect(EffectName.SWIRL,
68
    return
71 69

  
72 70
        "vec3 center = vUniforms[effect+1].yzw;                             \n"
73 71
      + "vec3 PS = center-v.xyz;                                            \n"
......
81 79
      + "vec4 SG = (1.0-deg1)*SO;                                           \n" // coordinates of the dilated circle P is going to get rotated around
82 80
      + "float d2 = max(0.0,degree(SG,PS2));                                \n" // make it a max(0,deg) because otherwise when center=left edge of the
83 81
                                                                                // object some points end up with d2<0 and they disappear off view.
84
      + "v.xy += deg1 * (PS.xy - PS2.xy/(1.0-d2));                          \n" // if d2=1 (i.e P=center) we should have P unchanged. How to do it?
85
      );
82
      + "v.xy += deg1 * (PS.xy - PS2.xy/(1.0-d2));                          \n";// if d2=1 (i.e P=center) we should have P unchanged. How to do it?
83
    }
84

  
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
// PUBLIC API
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
/**
89
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
90
 */
91
  public static void enable()
92
    {
93
    addEffect( NAME, code() );
86 94
    }
87 95

  
88 96
///////////////////////////////////////////////////////////////////////////////////////////////////
......
95 103
 */
96 104
  public VertexEffectSwirl(Data1D swirl, Data3D center, Data4D region)
97 105
    {
98
    super(EffectName.SWIRL);
106
    super(NAME);
99 107
    mSwirl  = swirl;
100 108
    mCenter = center;
101 109
    mRegion = (region==null ? MAX_REGION : region);
......
110 118
 */
111 119
  public VertexEffectSwirl(Data1D swirl, Data3D center)
112 120
    {
113
    super(EffectName.SWIRL);
121
    super(NAME);
114 122
    mSwirl  = swirl;
115 123
    mCenter = center;
116 124
    mRegion = MAX_REGION;

Also available in: Unified diff