ofeasycam current view mid point

I am plotting a videoplayer on the screen with ofnode extended. The videoplayers looks at the center of the screen. I am using ofeasycam to orbit around the cluster at a steady speed. Upon event fire I am changing the state to make to video come to the center grow in size using tweenzor.

I am not able to plot the position at the middle of the screen with a higher z value (relative to the camera). Tried multiple combinations.

<#>
//Would draw at the node position
if(playerState == VIDEO_HOVERING || playerState == VIDEO_CLOSED)
{

if(flag)
{
ofVec3f mehPoint = camUsed->worldToCamera(vidPlayerInitialPosition);
cout<<“INITIAL POSITION: “<<ofToString(mehPoint)<<”\n”;
flag = !flag;
}

hoverPlayerContainer.setFromCenter(camUsed->worldToCamera(vidPlayerInitialPosition), 70, 52.5);
hoverPlayer.draw(hoverPlayerContainer);
lookAt(vidPlayerlookAtPoint);
btnPlayerClose.draw();
}
else if(playerState == VIDEO_OPENING)
{
ofVec3f center=camUsed->getPosition().getScaled(5);
//
// float x=camUsed->getPosition().getNormalized().x;
// float y=camUsed->getPosition().getNormalized().y;
// float z=camUsed->getPosition().getNormalized().z;
float width=tweenParams.at(TWEEN_WIDTH);
float height=tweenParams.at(TWEEN_HEIGHT);

ofVec3f newPosition=center;
ofVec3f looks=newPosition.getScaled(1);
cout<<newPosition<<"\n";
ofSphere(looks.x,looks.y,looks.z,10);
ofLine(newPosition,looks);
hoverPlayerContainer.setFromCenter(newPosition, width, height);
ofPushMatrix();
lookAt(looks);
ofTranslate(newPosition.x,newPosition.y,newPosition.z);
setPosition(newPosition);
ofRotateX(tweenParams.at(TWEEN_ANGLE));
hoverPlayer.draw(hoverPlayerContainer);

ofPopMatrix();

}
</#>

HI, have you tried using cam.getZAxis()?
try this

  
ofVec3f boxPos = cam.getPosition() + cam.getZAxis()*dist;  

Where dist is any distance from the camera in it’s local z axis.

What ever you draw at boxPos will be at the middle of the screen at the distance defined by dist.

Thanks Roy,

I tried using the z axis. seems to give different outcome. I liked the idea but few questions if you dont mind

getZAxis returns me the local z axis of camera?

getPosition gives a real world position of the camera?

right now the position is some where beyond the cameras view. I think I am doing something wrong

VideoPlayer extends ofNode to setPosition and do lookAt.

  
  
enum VIDEO_ANIM {VIDEO_HOVERING, VIDEO_OPENED, VIDEO_OPENING, VIDEO_CLOSING,VIDEO_CLOSED};  
  
class VideoPlayer : public ofNode  
{  
    public:  
        VideoPlayer(string& _videoPath, int initialFrame, ofVec3f& initialPosition, ofVec3f& finalPosition, ofVec3f& lookAtPoint, float initWidth, float initHeight,vector<float>& xyz, ofEasyCam* sceneCam = NULL, float finalWidth = 900, float finalHeight = 677);  
        void loadMovie(string& _vidPath);  
        void setInitialFrame(int _curFrame);  
        void setPlayerPosition(ofVec3f& _pos);  
        void flipPlayerandPlayMovie();  
        void pauseMovie();  
        void update(ofEventArgs &e);  
        void play();  
        void stopMovieAndAnimatePlayer();  
        void setTransformationCam(ofEasyCam* cam);  
  
        //Draw functions  
        virtual void customDraw();  
        virtual ~VideoPlayer();  
        VIDEO_ANIM playerState;  
        bool animPlaying;  
  
  
    private:  
        ofVideoPlayer hoverPlayer;  
        ofEasyCam* camUsed;  
        ofRectangle hoverPlayerContainer;  
        string vidPlayerVideoPath;  
        int vidPlayerInitialFrame;  
        ofVec3f vidPlayerInitialPosition;  
        ofVec3f vidPlayerFinalPosition;  
        ofVec3f vidPlayerlookAtPoint;  
        float vidPlayerInitalWidth;  
        float vidPlayerInitialHeight;  
        float vidPlayerFinalWidth;  
        float vidPlayerFinalHeight;  
        bool flag;  
        vector<float>* xyzVals;  
  
};  
  
#endif // VIDEOPLAYER_H  
  
  

VideoPlayer.cpp

  
  
#include "VideoPlayer.h"  
  
  
  
  
  
void VideoPlayer::customDraw()  
{  
    //Would draw at the node position  
    if(camUsed)  
    {  
  
        //Would draw at the node position  
        if(playerState == VIDEO_HOVERING || playerState == VIDEO_CLOSED)  
        {  
            ofVec3f center=ofVec3f(0,0,0);  
            ofVec3f position=vidPlayerInitialPosition;  
            cout<<"pos"<<position<<"\n";  
            //position=camUsed->worldToCamera(position);  
            setPosition(position);  
            hoverPlayerContainer.setFromCenter(position, 67.5, 60.0);  
            xyzVals->at(1)=position.x;  
            xyzVals->at(2)=position.y;  
            xyzVals->at(3)=position.z;  
            hoverPlayer.draw(hoverPlayerContainer);  
            lookAt(center);  
  
        }  
        else if(playerState == VIDEO_OPENING)  
        {  
            ofVec3f center=camUsed->getPosition()+(camUsed->getZAxis()*150);  
//  
//            float x=camUsed->getPosition().getNormalized().x;  
//            float y=camUsed->getPosition().getNormalized().y;  
//            float z=camUsed->getPosition().getNormalized() .z;  
            float width=xyzVals->at(4);  
            float height=xyzVals->at(5);  
  
            ofVec3f newPosition=center;  
            ofVec3f looks=newPosition.getScaled(1);  
            cout<<"get:"<<newPosition<<"\n";  
            ofSphere(looks.x,looks.y,looks.z,10);  
            ofLine(newPosition,looks);  
            hoverPlayerContainer.setFromCenter(newPosition, width, height);  
            ofPushMatrix();  
            lookAt(looks);  
            ofTranslate(newPosition.x,newPosition.y,newPosition.z);  
            setPosition(newPosition);  
            ofRotateX(xyzVals->at(0));  
            hoverPlayer.draw(hoverPlayerContainer);  
  
            ofPopMatrix();  
  
  
        }  
        else  
        {  
  
  
            ofVec3f center=getPosition();  
  
  
            ofVec3f newPosition=center;  
            ofVec3f looks=newPosition.getScaled(-1);  
            cout<<newPosition<<"\n";  
            ofSphere(looks.x,looks.y,looks.z,10);  
            ofLine(newPosition,looks);  
  
            ofPushMatrix();  
            lookAt(looks);  
            //ofTranslate(newPosition.x,newPosition.y,newPosition.z);  
            //setPosition(newPosition);  
            hoverPlayer.draw(hoverPlayerContainer);  
  
            ofPopMatrix();  
  
        }  
    }  
}  
  
VideoPlayer::VideoPlayer(string& _videoPath, int initialFrame, ofVec3f& initialPosition, ofVec3f& finalPosition, ofVec3f& lookAtPoint, float initWidth, float initHeight,vector<float>& xyz, ofEasyCam* sceneCam, float finalWidth, float finalHeight)  
{  
    cout<<"Video Player constructor fired\n";  
    xyzVals=&xyz;  
    xyzVals->push_back(0);  
    xyzVals->push_back(initialPosition.x);  
    xyzVals->push_back(initialPosition.y);  
    xyzVals->push_back(initialPosition.z);  
    xyzVals->push_back(70);  
    xyzVals->push_back(50);  
    vidPlayerVideoPath = _videoPath;  
    vidPlayerInitialFrame = initialFrame;  
    vidPlayerInitialPosition = initialPosition; //center of the video player  
    vidPlayerFinalPosition = finalPosition;  
    vidPlayerInitalWidth = initWidth;  
    vidPlayerFinalWidth = finalWidth;  
    vidPlayerInitialHeight = initHeight;  
    vidPlayerFinalHeight = finalHeight;  
    vidPlayerlookAtPoint = lookAtPoint;  
    hoverPlayer.width = vidPlayerInitalWidth;  
    hoverPlayer.height = vidPlayerInitialHeight;  
  
    //Clickable params  
    camUsed = sceneCam;  
  
  
    loadMovie(_videoPath);  
    setInitialFrame(initialFrame);  
    //Set Player properties  
    ofNode::setPosition(initialPosition); //node (centre point of the video player at init position) from where the player has to lookAt  
  
    cout<<"Check videoPlayer Point Inside: "<<vidPlayerInitialPosition<<"\n";  
    hoverPlayerContainer.setFromCenter(initialPosition, vidPlayerInitalWidth, vidPlayerInitialHeight);  
    playerState = VIDEO_HOVERING;  
    animPlaying = false;  
    ofAddListener(ofEvents().update, this, &VideoPlayer::update);  
  
  
}  
  
void VideoPlayer::loadMovie(string& _vidPath)  
{  
    hoverPlayer.loadMovie(_vidPath);  
  
}  
  
void VideoPlayer::setInitialFrame(int _curFrame)  
{  
    hoverPlayer.setFrame(_curFrame);  
    hoverPlayer.setLoopState(OF_LOOP_NONE);  
}  
  
void VideoPlayer::update(ofEventArgs &e)  
{  
    //has to be hooked up with ofNotifyEvent(update event of baseApp)  
    hoverPlayer.update();  
  
}  
  
void VideoPlayer::play()  
{  
    hoverPlayer.play();  
}  
  
VideoPlayer::~VideoPlayer()  
{  
    cout<<"close Vid";  
    hoverPlayer.closeMovie();  
    hoverPlayer.close();  
}  
  
  

hi ofSMF,

getZAxis returns me the local z axis of camera?

YES

getPosition gives a real world position of the camera?

YES

right now the position is some where beyond the cameras view. I think I am doing something wrong

in line 31 of your VideoPlayer.cpp:

  
  ofVec3f center=camUsed->getPosition()+(camUsed->getZAxis()*150);    

you must multiply by a negative numer (in this case 150 should be negative) otherways you’ll get a position “on the back of the camera”.

I think you’re getting confused by the vector maths.

Question; I suspect that what you want to do is that the video player always faces the camera, and it is at the middle of the rendered image. am I right?
IS there anything going on inside update(ofEventArgs& e)?

when you use lookAt, the idea is that the ofNode (of ofCamera) rotates and looks towards the passed point.
Also, you should make all these transformations during the update before draw is called, otherwise the might not take effect.

Look at the comments I wrote in the code.

  
  if(camUsed)    
    {    
    
        //Would draw at the node position    
        if(playerState == VIDEO_HOVERING || playerState == VIDEO_CLOSED)    
        {    
            ofVec3f center=ofVec3f(0,0,0);    
            ofVec3f position=vidPlayerInitialPosition;    
            cout<<"pos"<<position<<"\n";    
            //position=camUsed->worldToCamera(position);    
            setPosition(position);    
            hoverPlayerContainer.setFromCenter(position, 67.5, 60.0);    
            xyzVals->at(1)=position.x;    
            xyzVals->at(2)=position.y;    
            xyzVals->at(3)=position.z;    
            hoverPlayer.draw(hoverPlayerContainer);    
            lookAt(center);  //this should be called before draw, during update, otherwise the rotation thats being calculated will ge passed to openGL during the next draw cycle, yet this will be forced to look at the origin, as center is 0,0,0.  
    
        }    
        else if(playerState == VIDEO_OPENING)    
        {    
            ofVec3f center=camUsed->getPosition()+(camUsed->getZAxis()*150);  // multiply by -150 not 150 to get a position in front of the camera.  
//    
//            float x=camUsed->getPosition().getNormalized().x;    
//            float y=camUsed->getPosition().getNormalized().y;    
//            float z=camUsed->getPosition().getNormalized() .z;    
            float width=xyzVals->at(4);    
            float height=xyzVals->at(5);    
    
            ofVec3f newPosition=center;    
            ofVec3f looks=newPosition.getScaled(1);    
            cout<<"get:"<<newPosition<<"\n";    
            ofSphere(looks.x,looks.y,looks.z,10);    
            ofLine(newPosition,looks);    
            hoverPlayerContainer.setFromCenter(newPosition, width, height);    
            ofPushMatrix();    
            lookAt(looks);  this must be called during the update, before draw  
            ofTranslate(newPosition.x,newPosition.y,newPosition.z); // by calling this and then hoverPlayer.draw(.....)  
hoverPlayerContainer will not get rendered incorrectly.  
            setPosition(newPosition);    
            ofRotateX(xyzVals->at(0));  //what's the idea of this?  
            hoverPlayer.draw(hoverPlayerContainer);    
    
            ofPopMatrix();    
    
    
        }    
        else    
        {    
    
    
            ofVec3f center=getPosition();    
    
    
            ofVec3f newPosition=center;    
            ofVec3f looks=newPosition.getScaled(-1);    
            cout<<newPosition<<"\n";    
            ofSphere(looks.x,looks.y,looks.z,10);    
            ofLine(newPosition,looks);    
    
            ofPushMatrix();    
            lookAt(looks);  //this will rotate the ofNode so it will always be facing the origin.  
            //ofTranslate(newPosition.x,newPosition.y,newPosition.z);    
            //setPosition(newPosition);    
            hoverPlayer.draw(hoverPlayerContainer);    
    
            ofPopMatrix();    
    
        }    
    }    

I think that you can get you’re project working with much less code.

Write me back if you need more help.

cheers!

Thanks a lot Ray,

I am new to openframeworks. Does making use of the update method make a lot difference?

[quote]You are right. I am orbiting the camera with constant increment in latitude. And on firing a click, the video has to flip open at the center. No matter where the camera is.

[/quote]

ofRotateX(xyzVals->at(0)); is done to give flip effect to the video player

I shall try your suggestions and get back

Thank you.

the thing is that you have to use a certain order for transformations, all the transformations that belong to ofNode (lookAt, orbit, etc) happen at a cpu level, once you call ofNode::draw() all its transformations are passed to the GPU, so any transformation you do inside customDraw will not have effect or will have in the next frame (depending on the data persistence ) that’s why you need to do all the transformations before draw.
if you try

  
setPosition(camUsed->getPosition()+(camUsed->getZAxis()*-150));//change -150 for whatever value is best for you      
lookAt(camUsed->getPosition());  
  

you should get your video player in front of the camera. Make sure you call this code during update, before draw.
You’ll just need to draw the video player in debug draw with out passing the ofRectangle instance, just draw it passing it its width and height. draw it without any transformation, as ofNode should take care of orienting and position it correctly.

Thanks a lot Roy,

It worked like a charm. Had to do some tweaks to get it working. Some trial and error based on assumptions.

From update when the state is opening i made this call

  
  
ofVec3f position=ofVec3f(tweenParams.at(TWEEN_X),tweenParams.at(TWEEN_Y),tweenParams.at(TWEEN_Z));  
    setPosition(position);  
    hoverCardContainer.setFromCenter(ofVec3f(0,0,0),tweenParams.at(TWEEN_WIDTH),tweenParams.at(TWEEN_HEIGHT));  
    lookAt(position.getRotated(tweenParams.at(TWEEN_ANGLE)+180,camUsed->getXAxis()));  
  

To set up the tween values I did this.

  
  
ofVec3f finalPosition=camUsed->getPosition()+(camUsed->getZAxis()*-400);  
    ofVec3f initialPosition=getPosition();  
    float animationTime=1.0f;  
    float finalWidth=444;  
    float finalHeight=250;  
    float delay=0.0f;  
    Tweenzor::add(&tweenParams.at(TWEEN_ANGLE),0.0f,360.0f,delay,animationTime);  
    Tweenzor::add(&tweenParams.at(TWEEN_X),initialPosition.x,finalPosition.x,delay,animationTime);  
    Tweenzor::add(&tweenParams.at(TWEEN_Y),initialPosition.y,finalPosition.y,delay,animationTime);  
    Tweenzor::add(&tweenParams.at(TWEEN_Z),initialPosition.z,finalPosition.z,delay,animationTime);  
    Tweenzor::add(&tweenParams.at(TWEEN_WIDTH),hoverCardContainer.getWidth(),finalWidth,delay,animationTime);  
    Tweenzor::add(&tweenParams.at(TWEEN_HEIGHT),hoverCardContainer.getHeight(),finalHeight,delay,animationTime);  
  

and finally in customDraw

  
  
 if(cardState == CARD_OPENING)  
        {  
                 cardImage.draw(hoverCardContainer);  
        }  
  

Great!
post some videos once finished.
:slight_smile: