2 * camera listener from XML
4 * License : The MIT License
5 * Copyright(c) 2013 MikuToga Partners
8 package jp.sfjp.mikutoga.vmd.model.xml;
10 import java.util.List;
11 import jp.sfjp.mikutoga.math.MkPos3D;
12 import jp.sfjp.mikutoga.vmd.model.BezierParam;
13 import jp.sfjp.mikutoga.vmd.model.CameraMotion;
14 import jp.sfjp.mikutoga.vmd.model.CameraRotation;
15 import jp.sfjp.mikutoga.vmd.model.PosCurve;
16 import jp.sfjp.mikutoga.vmd.model.VmdMotion;
17 import jp.sfjp.mikutoga.xml.SaxAttr;
18 import org.xml.sax.Attributes;
21 * カメラ関連のXML要素出現イベントを受信する。
23 class SaxCameraListener extends SaxVmdListener{
25 private CameraMotion currentCamera = null;
39 * @param tag {@inheritDoc}
40 * @param attr {@inheritDoc}
43 void openTag(VmdTag tag, Attributes attr){
46 openCameraMotion(attr);
49 openCameraTarget(attr);
52 openCameraRotation(attr);
55 openCameraRange(attr);
62 super.openTag(tag, attr);
71 * @param tag {@inheritDoc}
74 void closeTag(VmdTag tag){
80 setCurrentPosCurve(null);
85 setCurrentBezierParam(null);
96 * cameraMotion要素開始の通知。
99 private void openCameraMotion(Attributes attr){
100 this.currentCamera = new CameraMotion();
102 int frameNo = SaxAttr.getIntAttr(attr, XmlAttr.ATTR_FRAME);
103 this.currentCamera.setFrameNumber(frameNo);
105 boolean hasPerspective =
106 SaxAttr.getBooleanAttr(attr,
107 XmlAttr.ATTR_HAS_PERSPECTIVE,
109 this.currentCamera.setPerspectiveMode(hasPerspective);
115 * cameraMotion要素終了の通知。
117 private void closeCameraMotion(){
118 VmdMotion motion = getVmdMotion();
119 List<CameraMotion> cameraList = motion.getCameraMotionList();
120 cameraList.add(this.currentCamera);
122 this.currentCamera = null;
128 * cameraTarget要素開始の通知。
131 private void openCameraTarget(Attributes attr){
132 MkPos3D targetPos = this.currentCamera.getCameraTarget();
134 float xPos = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_X_POS);
135 float yPos = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_Y_POS);
136 float zPos = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_Z_POS);
138 targetPos.setPosition(xPos, yPos, zPos);
140 PosCurve curve = this.currentCamera.getTargetPosCurve();
141 setCurrentPosCurve(curve);
147 * cameraRotation要素開始の通知。
150 private void openCameraRotation(Attributes attr){
151 CameraRotation cameraRotation =
152 this.currentCamera.getCameraRotation();
154 float latitude = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_X_RAD);
155 float longitude = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_Y_RAD);
156 float roll = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_Z_RAD);
158 cameraRotation.setLatitude(latitude);
159 cameraRotation.setLongitude(longitude);
160 cameraRotation.setRoll(roll);
162 BezierParam bez = this.currentCamera.getIntpltRotation();
163 setCurrentBezierParam(bez);
169 * cameraRange要素開始の通知。
172 private void openCameraRange(Attributes attr){
173 float range = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_RANGE);
174 this.currentCamera.setRange(range);
176 BezierParam bez = this.currentCamera.getIntpltRange();
177 setCurrentBezierParam(bez);
186 private void openProjection(Attributes attr){
187 int vertDeg = SaxAttr.getIntAttr(attr, XmlAttr.ATTR_VERT_DEG);
188 this.currentCamera.setProjectionAngle(vertDeg);
190 BezierParam bez = this.currentCamera.getIntpltProjection();
191 setCurrentBezierParam(bez);