Browse Source

Added interpolator(s)

Added std::array (from tr1)
More Groups
master
Joshua Moerman 14 years ago
parent
commit
72dd50e0d2
  1. 37
      J.xcodeproj/project.pbxproj
  2. 4
      J/J.h
  3. 18
      J/array.h
  4. 119
      J/interpolator.h

37
J.xcodeproj/project.pbxproj

@ -14,6 +14,8 @@
425E9E02140A96C400A81A65 /* J.h in Headers */ = {isa = PBXBuildFile; fileRef = 4268136D140A321800CBF943 /* J.h */; settings = {ATTRIBUTES = (Public, ); }; };
42681369140A321800CBF943 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42681368140A321800CBF943 /* Foundation.framework */; };
4268136F140A321800CBF943 /* J.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4268136E140A321800CBF943 /* J.mm */; };
4283A45F14115AC400036A5D /* interpolator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4283A45E14115AC300036A5D /* interpolator.h */; };
4283A4641411707700036A5D /* array.h in Headers */ = {isa = PBXBuildFile; fileRef = 4283A4631411707700036A5D /* array.h */; };
42ED6A6B140A380000402F76 /* fbo.h in Headers */ = {isa = PBXBuildFile; fileRef = 42ED6A68140A380000402F76 /* fbo.h */; };
42ED6A6C140A380000402F76 /* shader.h in Headers */ = {isa = PBXBuildFile; fileRef = 42ED6A69140A380000402F76 /* shader.h */; };
42ED6A6D140A380000402F76 /* to_string.h in Headers */ = {isa = PBXBuildFile; fileRef = 42ED6A6A140A380000402F76 /* to_string.h */; };
@ -29,6 +31,8 @@
4268136C140A321800CBF943 /* J-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "J-Prefix.pch"; sourceTree = "<group>"; };
4268136D140A321800CBF943 /* J.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = J.h; sourceTree = "<group>"; };
4268136E140A321800CBF943 /* J.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = J.mm; sourceTree = "<group>"; };
4283A45E14115AC300036A5D /* interpolator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = interpolator.h; sourceTree = "<group>"; };
4283A4631411707700036A5D /* array.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = array.h; sourceTree = "<group>"; };
42ED6A68140A380000402F76 /* fbo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fbo.h; sourceTree = "<group>"; };
42ED6A69140A380000402F76 /* shader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shader.h; sourceTree = "<group>"; };
42ED6A6A140A380000402F76 /* to_string.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = to_string.h; sourceTree = "<group>"; };
@ -51,6 +55,7 @@
isa = PBXGroup;
children = (
42ED6A6A140A380000402F76 /* to_string.h */,
4283A4631411707700036A5D /* array.h */,
);
name = std;
path = J;
@ -87,11 +92,8 @@
4268136A140A321800CBF943 /* J */ = {
isa = PBXGroup;
children = (
425E9DF1140A74DA00A81A65 /* basic.h */,
425E9DF5140A774D00A81A65 /* basic.cpp */,
42ED6A68140A380000402F76 /* fbo.h */,
425E9DF8140A7EB400A81A65 /* fbo.mm */,
42ED6A69140A380000402F76 /* shader.h */,
4283A46114115AD400036A5D /* GL */,
4283A46214116ECB00036A5D /* utils */,
4268136D140A321800CBF943 /* J.h */,
4268136E140A321800CBF943 /* J.mm */,
);
@ -107,6 +109,26 @@
path = J;
sourceTree = "<group>";
};
4283A46114115AD400036A5D /* GL */ = {
isa = PBXGroup;
children = (
425E9DF1140A74DA00A81A65 /* basic.h */,
425E9DF5140A774D00A81A65 /* basic.cpp */,
42ED6A68140A380000402F76 /* fbo.h */,
425E9DF8140A7EB400A81A65 /* fbo.mm */,
42ED6A69140A380000402F76 /* shader.h */,
);
name = GL;
sourceTree = "<group>";
};
4283A46214116ECB00036A5D /* utils */ = {
isa = PBXGroup;
children = (
4283A45E14115AC300036A5D /* interpolator.h */,
);
name = utils;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@ -119,6 +141,8 @@
42ED6A6C140A380000402F76 /* shader.h in Headers */,
42ED6A6D140A380000402F76 /* to_string.h in Headers */,
425E9DF2140A74DA00A81A65 /* basic.h in Headers */,
4283A45F14115AC400036A5D /* interpolator.h in Headers */,
4283A4641411707700036A5D /* array.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -225,6 +249,7 @@
isa = XCBuildConfiguration;
buildSettings = {
DSTROOT = /tmp/J.dst;
GCC_DEBUGGING_SYMBOLS = full;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "J/J-Prefix.pch";
OTHER_LDFLAGS = "-ObjC";
@ -236,7 +261,9 @@
42681374140A321800CBF943 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/J.dst;
GCC_DEBUGGING_SYMBOLS = full;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "J/J-Prefix.pch";
OTHER_LDFLAGS = "-ObjC";

4
J/J.h

@ -8,6 +8,10 @@
#import <Foundation/Foundation.h>
#import "to_string.h"
#import "array.h"
#import "shader.h"
#import "fbo.h"
#import "interpolator.h"

18
J/array.h

@ -0,0 +1,18 @@
//
// array.h
// J
//
// Created by Joshua Moerman on 9/2/11.
// Copyright 2011 Vadovas. All rights reserved.
//
#ifndef J_array_h
#define J_array_h
#include <tr1/array>
namespace std {
using tr1::array;
}
#endif

119
J/interpolator.h

@ -0,0 +1,119 @@
//
// interpolator.h
// J
//
// Created by Joshua Moerman on 9/2/11.
// Copyright 2011 Vadovas. All rights reserved.
//
#ifndef J_interpolator_h
#define J_interpolator_h
#include <tr1/functional>
namespace J {
namespace interpolators {
struct linear{
template <typename T>
T operator()(T x){
return x;
}
};
struct cubic_in_out{
template <typename T>
T operator()(T x){
return 3*x*x - 2*x*x*x;
}
};
struct quintic_in_out{
template <typename T>
T operator()(T x){
return 6*x*x*x*x*x - 15*x*x*x*x + 10*x*x*x;
return x*x*x*(x*(x*6-15)+10);
}
};
struct cosine_in_out{
template <typename T>
T operator()(T x){
return 0.5f - 0.5f*std::cos(x*M_PI);
}
};
}
template <typename T>
class interpolator {
std::tr1::function<T (T)> ease_function;
size_t length;
size_t steps;
T value;
T begin_value;
T end_value;
public:
interpolator(T begin_value_ = T(0), size_t length_ = 100) :
ease_function(interpolators::cubic_in_out())
, length(length_)
, steps(0)
, value(begin_value_)
, begin_value(begin_value_)
, end_value(begin_value_) {}
template <typename F>
interpolator(T begin_value_, size_t length_, F ease_function_) :
ease_function(ease_function_)
, length(length_)
, steps(0)
, value(begin_value_)
, begin_value(begin_value_)
, end_value(begin_value_) {}
operator T&(){
return value;
}
operator T const () const{
return value;
}
void set_value(T new_value){
begin_value = value;
end_value = new_value;
steps = 0;
}
void set_length(size_t new_length){
T ratio = (T) steps / (T) length;
length = new_length;
steps = ratio*length;
}
template <typename F>
void set_ease_function(F new_ease_function){
ease_function = new_ease_function;
}
void interpolate(){
if(steps >= length) return;
++steps;
T ratio = (T) steps / (T) length;
ratio = ease_function(ratio);
value = (T(1) - ratio)*begin_value + ratio*end_value;
}
};
struct foo{
foo(int){}
};
} // namespace J
#endif