view UI code/6Dbox.h @ 38:fea11c3d1d94

tweaking endlessly
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 04 Dec 2014 17:03:01 +0000
parents 52dbd5b4cfa9
children 96ff7b41923a
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, bool showResultColor = false);
    void setHandTexture(ofImage* img);
    void setHandToDefaultTexture(){
        handTextureRef = &defaultImage;
    };

    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 = NULL);
    void animateToNewValues(vector<int> targetValues, float timeToTake, ofImage* newTexture = NULL);
    void animateHintToNewValues(Node targetValues, float timeToTake);
    void animateToNewValues(Node targetValues, float timeToTake);
    void setHintValues(vector<int> vals);
    void setValues(vector<int> vals);
    
    void draw();
    void showValueIndicator(bool showing){
        indicatorShowing = showing;
    };
    void flashScore(int score, ofColor col);
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, curHintPos;
    ofVec3f curRot, curHintRot;
    ofVec3f posAnimIncr;
    ofVec3f rotAnimIncr;
    ofVec3f hintposAnimIncr;
    ofVec3f hintrotAnimIncr;
    
    ofMesh handMesh;
    ofImage* handTextureRef;
    ofImage defaultImage;
    ofImage neutralPresetImage;
    ofImage hintImage;
    ofImage* hintImageRef;
    ofImage wallGrid;
    ofImage animImage;
    ofImage* animImageRef;
    ofMesh guideHandMesh;
    
    float hw, hh, hl, scale;
    float hintRoll, hintPitch, hintYaw;
    float minAngVal, maxAngVal;
    bool indicatorShowing;
    
    bool animatingHint;
    bool animatingIndicator;
    int showScoreForFrames;
};


#endif /* defined(__riftathon___Dbox__) */