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/VertexEffectPinch.java
34 34
 */
35 35
public class VertexEffectPinch extends VertexEffect
36 36
  {
37
  private static final EffectName NAME = EffectName.PINCH;
38

  
37 39
  private Data3D mPinch;
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 = mPinch.get(uniforms,index,currentDuration,step);
53
    boolean ret = mPinch.get(uniforms,index+VALUES_OFFSET,currentDuration,step);
52 54

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

  
56 58
    return ret;
57 59
    }
58 60

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
// PUBLIC API
61 61
///////////////////////////////////////////////////////////////////////////////////////////////////
62 62
// Pull P=(v.x,v.y) along a vector from the center of region sphere to a point on it defined by
63 63
// the (latitude,longitude) pair of angles with P' = P + (1-h)*dist(line to P)
64 64
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(line to P)
65 65
// (where 'line' above passes through the center point and goes along the vector)
66 66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
/**
68
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
69
 */
70
  public static void enable()
67

  
68
  static String code()
71 69
    {
72
    addEffect(EffectName.PINCH,
70
    return
73 71

  
74 72
        "vec3 ps = vUniforms[effect+1].yzw -v;               \n"
75 73
      + "float h         = vUniforms[effect].x;              \n"
......
93 91
      + "n_ps = sign_ps*n_ps/(dot_ps-(sign_ps-1.0));         \n" // uff! now n_ps is the parallel to ps component of n, even if ps==0
94 92
      + "float move = deg*(h-1.0)/(h/B+1.0/A);               \n" // move(0)=-A*deg, move(1)=0, move(inf)=B*deg
95 93
      + "n += move * abs(dot(n,dir)) * n_ps;                 \n"
96
      + "n = normalize(n);"
97
      );
94
      + "n = normalize(n);";
95
    }
96

  
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
// PUBLIC API
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
/**
101
 * Have to call this before the shaders get compiled (i.e before DistortedLibrary.onCreate()) for the Effect to work.
102
 */
103
  public static void enable()
104
    {
105
    addEffect( NAME, code() );
98 106
    }
99 107

  
100 108
///////////////////////////////////////////////////////////////////////////////////////////////////
......
109 117
 */
110 118
  public VertexEffectPinch(Data3D pinch, Data3D center, Data4D region)
111 119
    {
112
    super(EffectName.PINCH);
120
    super(NAME);
113 121
    mPinch  = pinch;
114 122
    mCenter = center;
115 123
    mRegion = (region==null ? MAX_REGION : region);
......
126 134
 */
127 135
  public VertexEffectPinch(Data3D pinch, Data3D center)
128 136
    {
129
    super(EffectName.PINCH);
137
    super(NAME);
130 138
    mPinch  = pinch;
131 139
    mCenter = center;
132 140
    mRegion = MAX_REGION;

Also available in: Unified diff