Hello everyone,
First of all, I’m really new to OF, and C++ ! (and pardon my english mistakes, not my first language !)
I’ve coded simple things before in Javascript and Processing, and I’m trying to learn C++ and OF now.
The reason I use C++ is I need to display HD video, and the others languages aren’t fast enough – and also that I’m simply curious to have more knowledge of programming
My code should display a continuous video made of about 20 different shots, with a random order determined in real time. Meaning at the end of each shot, the next shot is picked randomly in the video files.
(it should look like this : http://vimeo.com/102019579 – this is “faked” random in a cut video file of course)
I have made a simple example with only 3 videos, for starters, and managed to make it work. (I started with the videoplayer example of OF)
Now I wanted to add in a new rule, so that to identical shots could not follow each other. So, I need to have two random values, to compare the new generated to the old one, and regenerate if identical.
So this means, if I understood well, that I need to use pointers in order to keep track of the old value in two separate executions of the same function. Right ?
I tried that, but the compiler is giving me an error saying the pointer wasn’t declared even though I declared it in setup :
line 8 " ‘randNum’ was not declared in this scope "
There must be something I’m doing wrong with the pointers, because I’m new to this concept, but I can’t see what, and after a few hours of searching, I’m still stuck with no idea … so … any help would be very welcome
Here is my code in ofApp.cpp :
#include "math.h"
#include "ofApp.h"
void ofApp::loadAndPlay () {
//cout << " pointer in loadAndPlay function: " << randNum ; //adresse
*randNum = floor(ofRandom(3));
cout << *randNum;
switch(*randNum) {
case 0:
bikeMovie.loadMovie("movies/14.mov");
bikeMovie.setLoopState(OF_LOOP_NONE);
bikeMovie.play();
break;
case 1:
bikeMovie.loadMovie("movies/16.mov");
bikeMovie.setLoopState(OF_LOOP_NONE);
bikeMovie.play();
break;
default:
bikeMovie.loadMovie("movies/9.mov");
bikeMovie.setLoopState(OF_LOOP_NONE);
bikeMovie.play();
break;
}
}
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0,0,0);
unsigned int randomNumber(5);
//cout << "value : " << randomNumber ;
unsigned int *randNum(0);
//cout << " , empty pointer: " << randNum ;
randNum = &randomNumber ;
//cout << " , pointer : " << randNum ;
//cout << " , pointer value : " << *randNum ;
loadAndPlay();
}
//--------------------------------------------------------------
void ofApp::update(){
bikeMovie.update();
}
//--------------------------------------------------------------
void ofApp::draw(){
bikeMovie.draw(0,0);
if(bikeMovie.getIsMovieDone()){
loadAndPlay();
}
}
I don’t know whether it’s helpfull or not, but there are my ofApp.h and main.cpp :
#ifndef MATH_H_INCLUDED
#define MATH_H_INCLUDED
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void loadAndPlay();
ofVideoPlayer bikeMovie;
};
#endif // MATH_H_INCLUDED
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main( ){
ofSetupOpenGL(1024,768, OF_FULLSCREEN); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp( new ofApp());
}
Next I wanted to ask you about optimization, in order to display fluently HD 1080p videos, but first things first, as I can’t manage to make this work.
(about that, I was wondering if it’s best to have several files and play them next to each other, or to have the playhead moving randomly on indexed positions of one big file – in which case I would have to review my program almost from start !)
Thanks a lot for your help
Pablo