view UI code/6Dbox.h @ 29:e7af34b1af83

animated sliders throughput calculation
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 03 Nov 2014 18:27:58 +0000
parents 953db6518738
children a677c027e3a0
line wrap: on
line source
//
//  6Dbox.h
//  riftathon
//
//  Created by Robert Tubb on 27/10/2014.
//
//

#ifndef __riftathon___Dbox__
#define __riftathon___Dbox__
#include "3DboxGL.h"
#include "ofxVectormath.h"
#include <iostream>

struct Node {
    float x;
    float y;
    float z;
    float roll;
    float pitch;
    float yaw;
    
    void set(vector<float> vec){
        x = vec[0];
        y = vec[1];
        z = vec[2];
        roll = vec[3];
        pitch = vec[4];
        yaw = vec[5];
    }
    void setFromCC(vector<int> vec){
        float minVal = 0.;
        float maxVal = 127.;
        
        x =  (vec[0] - minVal)/(maxVal - minVal);
        y =  (vec[1] - minVal)/(maxVal - minVal);
        z =  (vec[2] - minVal)/(maxVal - minVal);
        
        roll =  57.3*  (2.0*(vec[3] - minVal)/(maxVal - minVal) - 1.0);
        pitch = - 57.3*  (2.0*(vec[4] - minVal)/(maxVal - minVal) - 1.0);
        yaw =    - 57.3*  (2.0*(vec[5] - minVal)/(maxVal - minVal) - 1.0);
    }
    vector<float> getAsVector(){
        vector<float> v;
        v.push_back(x);
        v.push_back(y);
        v.push_back(z);
        v.push_back(roll);
        v.push_back(pitch);
        v.push_back(yaw);
        return v;
    };
    ofVec3f getPositionVector(){
        ofVec3f v;
        v.x = x;
        v.y = y;
        v.z = z;
        return v;
    };
    ofVec3f getEulerRotVector(){
        ofVec3f v;
        v.x = roll;
        v.y = pitch;
        v.z = yaw;
        return v;
    };
};

class GuideHand {
    Node pose;
    
    ofMesh handMesh;
    ofImage* textureImageRef;
};

class Leap6DBox : public Leap3DBoxGL {
    
public:
    Leap6DBox(float ax,
                float ay,
                float awidth,
                float aheight,
                float azx,
                float azy,
                const UIProps& props);

    
    void drawIndicatorBlob(float x, float y, float z, ofColor c, bool isHint = false);
    void draw6DOFIndicatorBlob(float x, float y, float z, ofColor c, float r, float p, float yaw,ofImage* texImg);
    void setTexture(ofImage* img);
    
    void setValue(int index, int value);
    void setValueAndScale(int index, int value);
    
    void setHintValue(int which, int val);
    void setHintTexture(ofImage* img);
    void update();
    void animateHintToNewValues(vector<int> targetValues, float timeToTake, ofImage* newTexture);
    void animateHintToNewValues(Node targetValues, float timeToTake);
    void setHintValues(vector<int> vals);
    void setValues(vector<int> vals);
    
    void draw();
    void showValueIndicator(bool showing){
        indicatorShowing = showing;
    };

private:

    
    void drawIndicator();
    void draw3DCrossHairs(float x , float y, float z, ofColor c, bool isHint = false);
    
    void setUpHandMesh();
    void setUpThumb(ofPoint baseTR, ofPoint baseBR);
    void makeTexFace(ofPoint LT, ofPoint RT, ofPoint  RB, ofPoint LB);
    float rollVal, pitchVal, yawVal;
    ofMatrix4x4 getRotationQuat(float roll, float pitch, float yaw);
    
    ofVec3f curPos;
    ofVec3f curRot;
    ofVec3f posAnimIncr;
    ofVec3f rotAnimIncr;
    
    ofMesh handMesh;
    ofImage* defaultHandTextureRef;
    ofImage defaultImage;
    ofImage hintImage;
    ofImage* hintImageRef;
    ofMesh guideHandMesh;
    
    float hw, hh, hl, scale;
    float hintRoll, hintPitch, hintYaw;
    float minAngVal, maxAngVal;
    bool indicatorShowing;
    
    bool animating;
};


#endif /* defined(__riftathon___Dbox__) */