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();
}