2 * 3D bezier interpolation curve params
4 * License : The MIT License
5 * Copyright(c) 2011 MikuToga Partners
8 package jp.sfjp.mikutoga.vmd.model;
10 import java.text.MessageFormat;
13 * 三次ベジェ曲線による補間カーブを記述する。
14 * <p>制御点P0,P1,P2,P3の座標により記述される。
15 * <p>P0は(0,0)で固定。P3は(127,127)で固定。
16 * 残りのP1,P2は、P0,P3を対角線とする正方形の内部に位置しなければならない。
18 public class BezierParam {
21 * 制御点P1のXデフォルト値(直線補間)。
23 public static final byte DEF_P1X = 20;
25 * 制御点P1のYデフォルト値(直線補間)。
27 public static final byte DEF_P1Y = 20;
29 * 制御点P2のXデフォルト値(直線補間)。
31 public static final byte DEF_P2X = 107;
33 * 制御点P2のYデフォルト値(直線補間)。
35 public static final byte DEF_P2Y = 107;
38 * 制御点P1のXデフォルト値(EaseInOut)。
40 public static final byte EIO_P1X = 64;
42 * 制御点P1のYデフォルト値(EaseInOut)。
44 public static final byte EIO_P1Y = 0;
46 * 制御点P2のXデフォルト値(EaseInOut)。
48 public static final byte EIO_P2X = 64;
50 * 制御点P2のYデフォルト値(EaseInOut)。
52 public static final byte EIO_P2Y = 127;
57 public static final byte MIN_VAL = 0;
62 public static final byte MAX_VAL = 127;
64 private static final String MSG_TXT = "P1=({0}, {1}) P2=({2}, {3})";
67 private byte p1x = DEF_P1X;
68 private byte p1y = DEF_P1Y;
69 private byte p2x = DEF_P2X;
70 private byte p2y = DEF_P2Y;
75 * <p>デフォルトの直線補間が設定される。
86 public byte getP1x() {
94 public byte getP1y() {
102 public byte getP2x() {
110 public byte getP2y() {
116 * @param p1x 制御点P1のX座標
118 public void setP1x(byte p1x) {
125 * @param p1y 制御点P1のY座標
127 public void setP1y(byte p1y) {
134 * @param p2x 制御点P2のX座標
136 public void setP2x(byte p2x) {
143 * @param p2y 制御点P2のY座標
145 public void setP2y(byte p2y) {
152 * @param p1xArg 制御点P1のX座標
153 * @param p1yArg 制御点P1のY座標
155 public void setP1(byte p1xArg, byte p1yArg) {
163 * @param p2xArg 制御点P2のX座標
164 * @param p2yArg 制御点P2のY座標
166 public void setP2(byte p2xArg, byte p2yArg) {
174 * <p>P1,P2双方がP0-P3対角線上に存在する場合を直線補間とする。
177 public boolean isLinear(){
178 if(this.p1x != this.p1y) return false;
179 if(this.p2x != this.p2y) return false;
184 * MMDデフォルトの直線補間か判定する。
185 * @return MMDデフォルトの直線補間ならtrue
187 public boolean isDefaultLinear(){
188 if(this.p1x != DEF_P1X) return false;
189 if(this.p1y != DEF_P1Y) return false;
191 if(this.p2x != DEF_P2X) return false;
192 if(this.p2y != DEF_P2Y) return false;
198 * MMDデフォルトのEaseInOutカーブか判定する。
199 * @return MMDデフォルトのEaseInOutカーブならtrue
201 public boolean isDefaultEaseInOut(){
202 if(this.p1x != EIO_P1X) return false;
203 if(this.p1y != EIO_P1Y) return false;
205 if(this.p2x != EIO_P2X) return false;
206 if(this.p2y != EIO_P2Y) return false;
212 * MMDデフォルトの直線補間に設定する。
214 public void setDefaultLinear(){
223 * MMDデフォルトのEaseInOutカーブに設定する。
225 public void setDefaultEaseInOut(){
235 * @return {@inheritDoc}
238 public String toString(){
239 String msg = MessageFormat.format(MSG_TXT,
241 this.p2x, this.p2y );