ViewInfo.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00017 package com.generalrobotix.ui.view.tdview;
00018 
00019 import javax.media.j3d.*;
00020 import javax.vecmath.*;
00021 
00022 public class ViewInfo {
00023     /* View のモードを示すフラグ */
00024     public static final int VIEW_MODE_FIXED = 0;
00025     public static final int VIEW_MODE_WALK = 1;
00026     public static final int VIEW_MODE_ROOM = 2;
00027     public static final int VIEW_MODE_PARALLEL = 4;
00028     public static final int MODE_MASK =
00029         VIEW_MODE_WALK | VIEW_MODE_ROOM | VIEW_MODE_PARALLEL;
00030 
00031     public static final int FRONT_VIEW = 8;
00032     public static final int BACK_VIEW = 16;
00033     public static final int LEFT_VIEW = 32;
00034     public static final int RIGHT_VIEW = 64;
00035     public static final int TOP_VIEW = 128;
00036     public static final int BOTTOM_VIEW = 256;
00037     public static final int VIEW_MASK =
00038       FRONT_VIEW | BACK_VIEW | LEFT_VIEW | RIGHT_VIEW | TOP_VIEW | BOTTOM_VIEW;
00039 
00040     private int mode_;         // モード
00041     private double distance_;  // 原点からの距離
00042 
00043     protected Transform3D transform_;
00044 
00045     public double fieldOfView;
00046     public double frontClipDistance = 0.5;
00047     public double backClipDistance = 200;
00048 
00049     private ViewModeChangeListener listener_;
00050 
00056     public ViewInfo(int mode, double dist) {
00057         transform_ = new Transform3D();
00058         setDistance(dist);
00059         setViewMode(mode);
00060         setDirection(mode);
00061     }
00062 
00067     public void setViewMode(int mode) {
00068         if ((mode_ & VIEW_MASK) == VIEW_MODE_FIXED) return;
00069         mode_ = (mode & MODE_MASK) | (mode_ & VIEW_MASK);
00070         if (listener_ != null) {
00071             listener_.viewModeChanged(mode);
00072         }
00073     }
00074 
00079     public void setDistance(double dist) {
00080         distance_ = dist;
00081     }
00082 
00087     public void setDirection(int dir) {
00088         // VIEW_MODE_PARALELL以外のモードではセットできない
00089         //if ((mode_ & MODE_MASK) != VIEW_MODE_PARALLEL) return;
00090         mode_ = (mode_ & MODE_MASK) | (dir & VIEW_MASK);
00091         Matrix3d rot = new Matrix3d();
00092         Vector3d pos = new Vector3d();
00093         switch (mode_ & VIEW_MASK) {
00094         case FRONT_VIEW:
00095             pos.set(new double[]{distance_, 0.0, 0.0});
00096             rot.set(
00097                 new Matrix3d(
00098                     0.0, 0.0, 1.0,
00099                     1.0, 0.0, 0.0,
00100                     0.0, 1.0, 0.0
00101                 )
00102             );
00103             break;
00104         case BACK_VIEW:
00105             pos.set(new double[]{-distance_, 0.0, 0.0});
00106             rot.set(
00107                 new Matrix3d(
00108                     0.0, 0.0, -1.0,
00109                     -1.0, 0.0, 0.0,
00110                     0.0, 1.0, 0.0
00111                 )
00112             );
00113             break;
00114         case LEFT_VIEW:
00115             pos.set(new double[]{0.0, distance_, 0.0});
00116             rot.set(
00117                 new Matrix3d(
00118                     -1.0, 0.0, 0.0,
00119                     0.0, 0.0, 1.0,
00120                     0.0, 1.0, 0.0
00121                 )
00122             );
00123             break;
00124         case RIGHT_VIEW:
00125             pos.set(new double[]{0.0, -distance_, 0.0});
00126             rot.set(
00127                 new Matrix3d(
00128                     1.0, 0.0, 0.0,
00129                     0.0, 0.0, -1.0,
00130                     0.0, 1.0, 0.0
00131                 )
00132             );
00133             break;
00134         case TOP_VIEW:
00135             pos.set(new double[]{0.0, 0.0, distance_});
00136             rot.set(
00137                 new Matrix3d(
00138                     0.0, 1.0, 0.0,
00139                     -1.0, 0.0, 0.0,
00140                     0.0, 0.0, 1.0
00141                 )
00142             );
00143             break;
00144         case BOTTOM_VIEW:
00145             pos.set(new double[]{0.0, 0.0, -distance_});
00146             rot.set(
00147                 new Matrix3d(
00148                     0.0, 1.0, 0.0,
00149                     1.0, 0.0, 0.0,
00150                     0.0, 0.0, -1.0
00151                 )
00152             );
00153             break;
00154         }
00155         transform_.setTranslation(pos);
00156         transform_.setRotation(rot);
00157     }
00158 
00163     public int getViewMode() {
00164         return (mode_ & MODE_MASK);
00165     }
00166 
00167     public int getDirection() {
00168          return (mode_ & VIEW_MASK);
00169     }
00170 
00175     public Transform3D getTransform() {
00176         return transform_;
00177     }
00178 
00179     public void setTransform(Transform3D transform) {
00180         transform_.set(transform);
00181     }
00182 
00183     public void addViewModeChangeListener(ViewModeChangeListener listener) {
00184         listener_ = ViewModeChangeMulticaster.add(listener_, listener);
00185     }
00186 
00187     public void removeViewModeChangeListener(ViewModeChangeListener listener) {
00188         listener_ = ViewModeChangeMulticaster.remove(listener_, listener);
00189     }
00190 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:57