int tiledRenderer_Render( struct tiledRendererConfiguration * trConf) { struct VirtualStream * scene = (struct VirtualStream *) trConf->scenePTR; struct Model ** models = ( struct Model ** ) trConf->modelPTR; fprintf(stderr,"Photoshooting Object %u -> %s \n",trConf->objID,scene->object[trConf->objID].name); fprintf(stderr,"Rows/Cols %u/%u Distance %0.2f , Angles %0.2f %0.2f %0.2f\n",trConf->rows,trConf->columns,trConf->distance,trConf->angleX,trConf->angleY,trConf->angleZ); fprintf(stderr,"Angle Variance %0.2f %0.2f %0.2f\n",trConf->angXVariance,trConf->angYVariance,trConf->angZVariance); if (scene!=0) { setupTiledRendererOGL((float)scene->backgroundR,(float)scene->backgroundG,(float)scene->backgroundB); } else { setupTiledRendererOGL(0.0,0.0,0.0); } if (scene!=0) { unsigned char noColor=0; float posStack[POS_COORD_LENGTH]={0}; float R=1.0f , G=1.0f , B=0.0f , trans=0.0f; unsigned int i=trConf->objID; struct Model * mod = models[scene->object[i].type]; float * pos = (float*) &posStack; //This is a stupid way of passing stuff to be drawn R=1.0f; G=1.0f; B=1.0f; trans=0.0f; noColor=0; getObjectColorsTrans(scene,i,&R,&G,&B,&trans,&noColor); setModelColor(mod,&R,&G,&B,&trans,&noColor); mod->scale = scene->object[i].scale; int x,y,z; tiledRenderer_CalculateLoops(trConf); for (y=0; y<=trConf->op.snapsVertical; y++) { for (x=0; x<trConf->op.snapsHorizontal; x++) { tiledRenderer_get3DCenterForTile( trConf , x , y , &pos[POS_X],&pos[POS_Y],&pos[POS_Z], &pos[POS_ANGLEX],&pos[POS_ANGLEY],&pos[POS_ANGLEZ]); drawModelAt(mod,pos[POS_X],pos[POS_Y],pos[POS_Z],pos[POS_ANGLEX],pos[POS_ANGLEY],pos[POS_ANGLEZ]); } } fprintf(stderr,"Drawing stopped @ %0.2f %0.2f -> %0.2f %0.2f %0.2f \n",posStack[POS_X],posStack[POS_Y],pos[POS_ANGLEX],pos[POS_ANGLEY],pos[POS_ANGLEZ]); } glPopMatrix(); return 1 ; }
int drawAllSceneObjectsAtPositionsFromTrajectoryParser(struct VirtualStream * scene) { if (scene==0) { return 0; } if (checkOpenGLError(__FILE__, __LINE__)) { fprintf(stderr,"OpenGL error before calling drawAllObjectsAtPositionsFromTrajectoryParser\n"); } //unsigned int timestampToUse = scene->ticks*((unsigned int) 100/scene->rate); unsigned int timestampToUse = scene->timestampToUse; unsigned int i; for (i=1; i<scene->numberOfObjects; i++) { if (scene->object[i].numberOfFrames<=1) { scene->object[i].lastFrame = 0; } else { scene->object[i].lastFrame = scene->ticks % scene->object[i].numberOfFrames; } } doAllEventTriggers(timestampToUse); //This is actually the only visible console output.. if (scene->ticks%10==0) { fprintf(stderr,"\r%0.2f FPS - @ %0.2f sec ( %u ticks * %u microseconds [ rate %0.2f ] ) \r", scene->controls.lastFramerate, (float) timestampToUse/1000, scene->ticks, scene->controls.tickUSleepTime, scene->rate ); } //--------------------------------------------------- /* int viewport[4]; float modelview[16]; float projection[16]; glGetFloatv( GL_MODELVIEW_MATRIX, modelview ); glGetFloatv( GL_PROJECTION_MATRIX, projection ); glGetIntegerv( GL_VIEWPORT, viewport ); print4x4FMatrix("Projection",projection); print4x4FMatrix("ModelView",modelview);*/ int enableTransformedRendering=1; unsigned char noColor=0; float posStackA[7]={0}; float posStackB[7]={0}; float scaleX=1.0,scaleY=1.0,scaleZ=1.0; float R=1.0f , G=1.0f , B=0.0f , trans=0.0f; float * joints=0; //Object 0 is camera , so we draw object 1 To numberOfObjects-1 for (i=1; i<scene->numberOfObjects; i++) { unsigned int objectType_WhichModelToDraw = scene->objectTypes[scene->object[i].type].modelListArrayNumber; unsigned int numberOfBones = scene->objectTypes[scene->object[i].type].numberOfBones; if (objectType_WhichModelToDraw<modelStorage->currentNumberOfModels) { struct Model * mod = &modelStorage->models[objectType_WhichModelToDraw]; //fprintf(stderr,"Drawing model %u/%u ( %s ) \n",objectType_WhichModelToDraw ,modelStorage->currentNumberOfModels,mod->pathOfModel); float * pos = (float*) &posStackA; if (numberOfBones>0) { //The 4x4 Matrix per joint joints=(float *) malloc(sizeof(float) * numberOfBones * 16); //memset(joints,0,sizeof(float) * numberOfBones * 16); //Clear it .. //We initialize Identity Matrices everywhere.. unsigned int z; for (z=0; z<(numberOfBones); z++) { float * mat = &joints[16*z]; mat[0]=1.0; mat[1]=0.0; mat[2]=0.0; mat[3]=0.0; mat[4]=0.0; mat[5]=1.0; mat[6]=0.0; mat[7]=0.0; mat[8]=0.0; mat[9]=0.0; mat[10]=1.0; mat[11]=0.0; mat[12]=0.0; mat[13]=0.0; mat[14]=0.0; mat[15]=1.0; } } if ( calculateVirtualStreamPos(scene,i,timestampToUse,pos,joints,&scaleX,&scaleY,&scaleZ) ) { //This is a stupid way of passing stuff to be drawn R=1.0f; G=1.0f; B=1.0f; trans=0.0f; noColor=0; getObjectColorsTrans(scene,i,&R,&G,&B,&trans,&noColor); //fprintf(stderr,"Object %s should be RGB(%0.2f,%0.2f,%0.2f) , Transparency %0.2f , ColorDisabled %u\n",scene->object[i].name,R,G,B,trans,noColor); setModelColor(mod,&R,&G,&B,&trans,&noColor); mod->scaleX = scaleX;//scene->object[i].scale; mod->scaleY = scaleY;//scene->object[i].scale; mod->scaleZ = scaleZ;//scene->object[i].scale; mod->wireframe = scene->renderWireframe; mod->showSkeleton = scene->showSkeleton; mod->highlight = ( scene->selectedObject == i ); //fprintf(stderr,"Model %s is now RGB(%0.2f,%0.2f,%0.2f) , Transparency %0.2f , ColorDisabled %u\n",scene->object[i].name, mod->colorR, mod->colorG, mod->colorB, mod->transparency,mod->nocolor ); //fprintf(stderr,"Draw OBJ%u(%f %f %f , %f %f %f %f , trans %f )\n",i,pos[0],pos[1],pos[2],pos[3],pos[4],pos[5],pos[6],trans); if (scene->debug) { print3DPoint2DWindowPosition(i , pos[0],pos[1],pos[2] ); } if ( (modelHasASkinTransformation(mod,joints)) && (enableTransformedRendering) ) { //We need to do joint transforms before draw //fprintf(stderr,"Doing joint transforms..!\n"); struct TRI_Model triModelOut={0}; struct TRI_Model *triModelIn=(struct TRI_Model*) mod->modelInternalData; doModelTransform( &triModelOut , triModelIn , joints , numberOfBones , 1/*Autodetect default matrices for speedup*/ , 1/*Direct setting of matrices*/, 1/*Do Transforms, don't just calculate the matrices*/ , 0 /*Default joint convention*/ ); //fprintf(stderr,"TriOUT Indices %u , TriIN Indices %u \n",triModelOut.header.numberOfIndices,triModelIn->header.numberOfIndices); mod->modelInternalData = (void*) &triModelOut; // - - - - // pX pY pZ rX rY rZ if (! drawModelAt(mod,pos[0],pos[1],pos[2],pos[3],pos[4],pos[5],mod->rotationOrder) ) { fprintf(stderr,RED "Could not draw object %u , type %u \n" NORMAL ,i , objectType_WhichModelToDraw ); } // - - - - mod->modelInternalData = (void*) triModelIn; deallocInternalsOfModelTri(&triModelOut); } else { //Regular <fast> drawing of model // pX pY pZ rX rY rZ if (! drawModelAt(mod,pos[0],pos[1],pos[2],pos[3],pos[4],pos[5],mod->rotationOrder) ) { fprintf(stderr,RED "Could not draw object %u , type %u \n" NORMAL ,i , objectType_WhichModelToDraw ); } } scene->object[i].bbox2D[0] = mod->bbox2D[0]; scene->object[i].bbox2D[1] = mod->bbox2D[1]; scene->object[i].bbox2D[2] = mod->bbox2D[2]; scene->object[i].bbox2D[3] = mod->bbox2D[3]; } else { fprintf(stderr,YELLOW "Could not determine position of object %s (%u) , so not drawing it\n" NORMAL,scene->object[i].name,i); } if (joints!=0) { free(joints); joints=0; } if (checkOpenGLError(__FILE__, __LINE__)) { fprintf(stderr,"OpenGL error after drawing object %u \n",i); } } else { fprintf(stderr,YELLOW "Scene object %u/%u ( %s ) points to unallocated model %u/%u , cannot draw it\n" NORMAL,i,scene->numberOfObjects,scene->object[i].name , objectType_WhichModelToDraw , modelStorage->currentNumberOfModels ); } } drawAllConnectors(scene , timestampToUse , scaleX, scaleY, scaleZ); return 1; }
void drawModel(struct Model * mod) { if (mod == 0) { fprintf(stderr,"Cannot draw model , it doesnt exist \n"); return ; } //If mod = 0 accesing the fields below will lead in crashing.. drawModelAt(mod,mod->x,mod->y,mod->z,mod->heading,mod->pitch,mod->roll); }