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 * 三次ベジェ曲線による補間カーブを記述する。
15 * <p>制御点P0,P1,P2,P3の座標により記述される。
17 * <p>P0は(0,0)で固定。P3は(127,127)で固定。
18 * 残りのP1,P2は、P0,P3を対角線とする正方形の内部に位置しなければならない。
20 public class BezierParam {
23 * 制御点P1のXデフォルト値(直線補間)。
25 public static final byte DEF_P1X = 20;
27 * 制御点P1のYデフォルト値(直線補間)。
29 public static final byte DEF_P1Y = 20;
31 * 制御点P2のXデフォルト値(直線補間)。
33 public static final byte DEF_P2X = 107;
35 * 制御点P2のYデフォルト値(直線補間)。
37 public static final byte DEF_P2Y = 107;
40 * 制御点P1のXデフォルト値(EaseInOut)。
42 public static final byte EIO_P1X = 64;
44 * 制御点P1のYデフォルト値(EaseInOut)。
46 public static final byte EIO_P1Y = 0;
48 * 制御点P2のXデフォルト値(EaseInOut)。
50 public static final byte EIO_P2X = 64;
52 * 制御点P2のYデフォルト値(EaseInOut)。
54 public static final byte EIO_P2Y = 127;
59 public static final byte MIN_VAL = 0;
64 public static final byte MAX_VAL = 127;
66 private static final String MSG_TXT = "P1=({0}, {1}) P2=({2}, {3})";
69 private byte p1x = DEF_P1X;
70 private byte p1y = DEF_P1Y;
71 private byte p2x = DEF_P2X;
72 private byte p2y = DEF_P2Y;
78 * <p>デフォルトの直線補間が設定される。
90 public byte getP1x() {
99 public byte getP1y() {
108 public byte getP2x() {
117 public byte getP2y() {
124 * @param p1x 制御点P1のX座標
126 public void setP1x(byte p1x) {
134 * @param p1y 制御点P1のY座標
136 public void setP1y(byte p1y) {
144 * @param p2x 制御点P2のX座標
146 public void setP2x(byte p2x) {
154 * @param p2y 制御点P2のY座標
156 public void setP2y(byte p2y) {
164 * @param p1xArg 制御点P1のX座標
165 * @param p1yArg 制御点P1のY座標
167 public void setP1(byte p1xArg, byte p1yArg) {
176 * @param p2xArg 制御点P2のX座標
177 * @param p2yArg 制御点P2のY座標
179 public void setP2(byte p2xArg, byte p2yArg) {
188 * <p>P1,P2双方がP0-P3対角線上に存在する場合を直線補間とする。
192 public boolean isLinear(){
193 if(this.p1x != this.p1y) return false;
194 if(this.p2x != this.p2y) return false;
199 * MMDデフォルトの直線補間か判定する。
201 * @return MMDデフォルトの直線補間ならtrue
203 public boolean isDefaultLinear(){
204 if(this.p1x != DEF_P1X) return false;
205 if(this.p1y != DEF_P1Y) return false;
207 if(this.p2x != DEF_P2X) return false;
208 if(this.p2y != DEF_P2Y) return false;
214 * MMDデフォルトのEaseInOutカーブか判定する。
216 * @return MMDデフォルトのEaseInOutカーブならtrue
218 public boolean isDefaultEaseInOut(){
219 if(this.p1x != EIO_P1X) return false;
220 if(this.p1y != EIO_P1Y) return false;
222 if(this.p2x != EIO_P2X) return false;
223 if(this.p2y != EIO_P2Y) return false;
229 * MMDデフォルトの直線補間に設定する。
231 public void setDefaultLinear(){
240 * MMDデフォルトのEaseInOutカーブに設定する。
242 public void setDefaultEaseInOut(){
253 * @return {@inheritDoc}
256 public String toString(){
257 String msg = MessageFormat.format(MSG_TXT,
259 this.p2x, this.p2y );