By AlessandroB
on Fri, 04/12/2013 - 14:39
The VideoPlayback sample somes with two video files that are associated to two image targets. This article explains what are the necessary code changes to add a third video and associate it to a third image target.
VideoPlayback.java:
- open VideoPlayback.java:
- modify the NUM_TARGETS value to 3 or more (now it is set to 2)
- add a definition for an extra target next to CHIPS and STONES, i.e. update the following code:
public static final int NUM_TARGETS = 3; // was 2, set it to 3 (or higher, for more videos) public static final int STONES = 0; public static final int CHIPS = 1; public static final int MY_TARGET = 2; // added code
- Add the filename of your new movie in mMovieNames, i.e.:
MovieName[STONES] = "VuforiaSizzleReel_1.m4v"; mMovieName[CHIPS] = "VuforiaSizzleReel_2.m4v"; mMovieName[MY_TARGET] = "My_Movie.m4v"; // YOUR VIDEO
VideoPlayback.cpp:
- Update the definitions of NUM_TARGETS and the target names as follow:
static const int NUM_TARGETS = 3; //was 2 in original sample code, set it to 3 or more static const int STONES = 0; static const int CHIPS = 1; static const int MY_TARGET = 2; //new line of code for my target
- Update this code (in the initRendering function):
keyframeQuadAspectRatio[STONES] = (float)textures[0]->mHeight / (float)textures[0]->mWidth; keyframeQuadAspectRatio[CHIPS] = (float)textures[1]->mHeight / (float)textures[1]->mWidth; //add line of code for my target keyframeQuadAspectRatio[MY_TARGET] = (float)textures[2]->mHeight / (float)textures[2]->mWidth;
- In the renderFrame function, update the code to determine the currentTarget as follows:
if (strcmp(imageTarget.getName(), "stones") == 0) currentTarget=STONES; else if (strcmp(imageTarget.getName(), "chips") == 1) currentTarget=CHIPS; else currentTarget=MY_TARGET;
Similarly, update the code involving the glVertexAtribPointer functions:
if (strcmp(imageTarget.getName(), "stones") == 0) glVertexAttribPointer(videoPlaybackTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &videoQuadTextureCoordsTransformedStones[0]); else if (strcmp(imageTarget.getName(), "chips") == 0) glVertexAttribPointer(videoPlaybackTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &videoQuadTextureCoordsTransformedChips[0]); else glVertexAttribPointer(videoPlaybackTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &videoQuadTextureCoordsTransformed_My_Target[0]);
- Add this definition at the beginning of VideoPlayback.cpp (next to the other two definitions for "chips" and "stones"):
GLfloat videoQuadTextureCoordsTransformed_My_Target[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, };
- Update the setVideoDimensions function to account the MY_TARGET case (next to CHIPS and STONES)