Esempio n. 1
0
File: main.c Progetto: pavelfryz/fit
 void renderScene()
{
    /* test existence frame bufferu a modelu */
    IZG_ASSERT(polymodel && renderer);

    /* nastavit projekcni matici */
    trProjectionPerspective(renderer->camera_dist, renderer->frame_w, renderer->frame_h);

    /* vycistit model matici */
    trLoadIdentity();

    /* nejprve nastavime posuv cele sceny od/ke kamere */
    trTranslate(0.0, 0.0, renderer->scene_move_z);

    /* natoceni cele sceny - jen ve dvou smerech - mys je jen 2D... :( */
    trRotateX(renderer->scene_rot_x);
    trRotateY(renderer->scene_rot_y);

    /* nastavime material */
    renMatAmbient(renderer, &MAT_RED_AMBIENT);
    renMatDiffuse(renderer, &MAT_RED_DIFFUSE);
    renMatSpecular(renderer, &MAT_RED_SPECULAR);

    /* a vykreslime nas model */
    renderModel();
}
Esempio n. 2
0
void ModelRender::renderShadow(const Matrix4f &mvp, unsigned int)
{
    program.bind();
    Matrix4f mat=mvp;

    glEnableVertexAttribArray(attribute_v_coord);
    glEnableVertexAttribArray(attribute_normal);
    glEnableVertexAttribArray(attribute_texcoord);

    Model * tmp;
    while(base->renderCount()>0)
    {
        tmp=base->popRender();
        mat=tmp->getMatrix()*mvp;

        program.uniformMatrix(uniform_mvp,mat);
        renderModel(tmp);
        tmp=tmp->next;
    }

    glDisableVertexAttribArray(attribute_v_coord);
    glDisableVertexAttribArray(attribute_normal);
    glDisableVertexAttribArray(attribute_texcoord);

    program.unbind();
}
Esempio n. 3
0
Void TAppRendererTop::go()
{
  switch ( m_iRenderMode )
  {
  case 0:
    render();
    break;
#if H_3D_VSO
  case 1:
    renderModel();
    break;
#endif
  case 10:
    renderUsedPelsMap( );
      break;
  default:
    AOT(true);
  }

#if H_3D_REN_MAX_DEV_OUT
  Double dMaxDispDiff = m_cCameraData.getMaxShiftDeviation(); 

  if ( !(dMaxDispDiff < 0) )
  {  
    printf("\n Max. possible shift error: %12.3f samples.\n", dMaxDispDiff );
  }
#endif
}
Esempio n. 4
0
    bool Animator::doInitialize()
    {
        loadAreaFromTDF("Animator", "gui/animator.area");
        gfx->set_2D_mode();

        anim_data.load(nb_obj());

            // Initialize renderer
        getTexture();

        cam.pos.z = 10.0f;
        cam.pos.x = cam.pos.y = 0.0f;
        cam.dir.z = -1.0f;
        cam.dir.x = cam.dir.y = 0.0f;
        cam.setMatrix(Scale(1.0f));

        r1 = 0.0f, r2 = 0.0f, r3 = 0.0f;
        zoom = 0.1f;
        amx = mouse_x;
        amy = mouse_y;
        amz = mouse_z;
        sel_idx = -1;
        cursor_idx = -1;
        pointing_mode = ANIMATOR_MODE_SELECTION;

        renderModel();
        return true;
    }
Esempio n. 5
0
void renderStudentScene(S_Renderer *pRenderer, S_Model *pModel)
{
	/* test existence frame bufferu a modelu */
	IZG_ASSERT(pModel && pRenderer);

	/* nastavit projekcni matici */
	trProjectionPerspective(pRenderer->camera_dist, pRenderer->frame_w, pRenderer->frame_h);

	/* vycistit model matici */
	trLoadIdentity();

	/* nejprve nastavime posuv cele sceny od/ke kamere */
	trTranslate(0.0, 0.0, pRenderer->scene_move_z);

	/* nejprve nastavime posuv cele sceny v rovine XY */
	trTranslate(pRenderer->scene_move_x, pRenderer->scene_move_y, 0.0);

	/* natoceni cele sceny - jen ve dvou smerech - mys je jen 2D... :( */
	trRotateX(pRenderer->scene_rot_x);
	trRotateY(pRenderer->scene_rot_y);

	/* nastavime material */
	/*
	renMatAmbient(pRenderer, &MAT_RED_AMBIENT);
	renMatDiffuse(pRenderer, &MAT_RED_DIFFUSE);
	renMatSpecular(pRenderer, &MAT_RED_SPECULAR);
	//*/
	renMatAmbient(pRenderer, &MAT_WHITE_AMBIENT);
	renMatDiffuse(pRenderer, &MAT_WHITE_DIFFUSE);
	renMatSpecular(pRenderer, &MAT_WHITE_SPECULAR);

	/* a vykreslime nas model (ve vychozim stavu kreslime pouze snimek 0) */
	renderModel(pRenderer, pModel, myStudFrame);
}
Esempio n. 6
0
void CCObject::renderObject(const CCCameraBase *camera, const bool alpha)
{	
    if( shouldRender )
    {
        if( alpha == false || transparentParent )
        {
            GLPushMatrix();
            {
                refreshModelMatrix();
                GLMultMatrixf( modelMatrix );

                if( alpha == transparent )
                {
                    renderModel( alpha );
                }
                
                for( int i=0; i<children.length; ++i )
                {
                    children.list[i]->renderObject( camera, alpha );
                }
            }
            GLPopMatrix();
        }
    }
}
Esempio n. 7
0
char readChunk(Chunk *chunk, FILE *in) {
    RLE_BlockData buf;
    BlockData data;
    int count = 0, size, i = 0;
    Block *block;

    while (count < CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE) {
        size = fread(&buf, sizeof(buf), 1, in);

        if (!size) { // file too short
            fprintf(stderr, "Error reading world file");
            if (feof(in)) fputs("; file too short", stderr);
            else if (ferror(in)) fputs("; an error occured", stderr);
            fputs("\n", stderr);
            return 0;
        }

        // printf("read %d blocks\n", buf.count);

        count += buf.count;
        data = buf.data;

        while (buf.count > 0 && i < CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE) {
            block = &chunk->blocks_lin[i];

            if (data.logic) {
                block->logic = calloc(1, sizeof(Logic));

                block->logic->type = data.logic_type;
                block->logic->roll = data.logic_roll;
                block->logic->pitch = data.logic_pitch;
                block->logic->yaw = data.logic_yaw;

                updateLogicModel(block);
            }

            if (data.data) {
                block->data = createModel();
                block->data->chunk = createChunk(0, 0, 0);
                block->active = 1;
                if (!readChunk(block->data->chunk, in))
                    return 0;
                renderModel(block->data);
            }

            block->color = data.color;
            if (data.color.all) {
                block->active = 1;
            }

            i++;
            buf.count--;
        }
    }

    renderChunk(chunk);

    return 1;
}
Esempio n. 8
0
void Viewer::onRender()
{
  // clear the vertex and face counters
  m_vertexCount = 0;
  m_faceCount = 0;

  // clear all the buffers
  glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // set the projection transformation
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0f, (GLdouble)m_width / (GLdouble)m_height, m_scale * 50.0, m_scale * 1000.0);

  // set the model transformation
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // light attributes
  const GLfloat light_ambient[]  = { 0.3f, 0.3f, 0.3f, 1.0f };
  const GLfloat light_diffuse[]  = { 0.52f, 0.5f, 0.5f, 1.0f };
  const GLfloat light_specular[] = { 0.1f, 0.1f, 0.1f, 1.0f };

  // setup the light attributes
  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

  // set the light position
  GLfloat lightPosition[] = { 0.0f, -1.0f, 1.0f, 1.0f };
  glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);

  // set camera position
  glTranslatef(0.0f, 0.0f, -m_distance * m_scale);
  glRotatef(m_tiltAngle, 1.0f, 0.0f, 0.0f);
  glRotatef(m_twistAngle, 0.0f, 0.0f, 1.0f);
  glTranslatef(0.0f, 0.0f, -90.0f * m_scale);
  glTranslatef(0.0f, 0.0f, m_camheight);

  // render the model
  renderModel();

  // render the cursor
  renderCursor();

  // swap the front- and back-buffer
  glutSwapBuffers();
  
  // increase frame counter
  m_fpsFrames++;  

  //printf("%d\n",m_fps);
}
Esempio n. 9
0
Model *ModelRender::selectModel(int x, int y,const Camera & camera)
{
    glClearStencil(255);

    glEnable(GL_STENCIL_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

    program.bind();
    Matrix4f mat;

    glEnableVertexAttribArray(attribute_v_coord);
    glEnableVertexAttribArray(attribute_normal);
    glEnableVertexAttribArray(attribute_texcoord);

    Model * models[255];

    GLuint cnt=0;
    Model * tmp;
    while(base->renderCount()>0 && cnt<255)
    {
        tmp=base->popRender();
        models[cnt]=tmp;
        mat=tmp->getMatrix()*camera.getLook();

        program.uniformMatrix(uniform_mvp,mat);

        glStencilFunc(GL_ALWAYS, cnt, -1);
        renderModel(tmp);
        tmp=tmp->next;
        cnt++;
    }

    glDisableVertexAttribArray(attribute_v_coord);
    glDisableVertexAttribArray(attribute_normal);
    glDisableVertexAttribArray(attribute_texcoord);

    program.unbind();
    //selecting
    GLuint index;
    glReadPixels(x, camera.height() - y - 1, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_INT, &index);

    glDisable(GL_STENCIL_TEST);

    base->clearRender();
    if(index < cnt)
    {
        return models[index];
    }
    return NULL;
}
Esempio n. 10
0
void ModelRender::render(const Matrix4f &mvp, unsigned int)
{
    program.bind();
    Matrix4f mat=mvp;
    Matrix4f nmat;
    Matrix3f mv;

    glEnableVertexAttribArray(attribute_v_coord);
    glEnableVertexAttribArray(attribute_normal);
    glEnableVertexAttribArray(attribute_texcoord);

    Model * tmp;
    while(base->renderCount()>0)
    {
        tmp=base->popRender();
        mat=tmp->getMatrix()*mvp;

        nmat=tmp->getMatrix();
        nmat.inverse();

        mv[0]=nmat[0];
        mv[1]=nmat[1];
        mv[2]=nmat[2];

        mv[3]=nmat[4];
        mv[4]=nmat[5];
        mv[5]=nmat[6];

        mv[6]=nmat[8];
        mv[7]=nmat[9];
        mv[8]=nmat[10];
        mv.transpose();

        program.uniform(uniform_selected,tmp->isSelected());
        program.uniformMatrix(uniform_mvp,mat);
        program.uniformMatrix(uniform_mv,mv);

        renderModel(tmp);
        tmp=tmp->next;
    }

    glDisableVertexAttribArray(attribute_v_coord);
    glDisableVertexAttribArray(attribute_normal);
    glDisableVertexAttribArray(attribute_texcoord);

    program.unbind();
}
Esempio n. 11
0
void Earth::draw()
{
    glPushMatrix();
    glEnable(GL_TEXTURE_2D);
    
    //glPushMatrix();
    glTranslatef(m_position.x, m_position.y, m_position.z); //Move back to the actual position
    glScalef(m_scalefactor, m_scalefactor, m_scalefactor);
    glRotatef(m_rotation.y , 0.0, 1.0, 0.0);
    glRotatef(m_rotation.x , 1.0, 0.0, 0.0);
    glTranslatef(m_position.x - 200, 0.0f, 0.0f); //Move to origin
    //glPopMatrix();
    
    renderModel();
    glDisable(GL_TEXTURE_2D);
    glPopMatrix();
}
void SceneRenderer::renderScene(HDC hDc,Camera glCamera,std::vector<Renderable> objects)
{
	glm::mat4 object_model_matrix;
	glm::mat4 mvp_matrix;
	glm::mat4 camera_mvp_matrix = glCamera.getMVPMatrix();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	if (shader) shader->begin();

	for(std::vector<Renderable>::iterator object = objects.begin(); object != objects.end(); object++)
	{
		object_model_matrix = object->getModelMatrix();
		mvp_matrix = camera_mvp_matrix * object_model_matrix;
		shader->setUniformMatrix4fv("mvp_matrix",1,GL_FALSE,&mvp_matrix[0][0]);
		renderModel(object->getModel());
	}
	if (shader) shader->end();
	SwapBuffers(hDc);
}
Esempio n. 13
0
void ModelRenderer::renderOne(const ResourcePtr& resource,
    const glm::mat4& projectionMat,
    const glm::mat4& viewMat,
    const glm::mat4& worldMat)
{
    if(resource->resourceType() == ResourceType::kSetup)
    {
        renderSetup(resource->cast<Setup>(),
            projectionMat,
            viewMat,
            worldMat);
    }
    else if(resource->resourceType() == ResourceType::kModel)
    {
        renderModel(resource->cast<Model>(),
            projectionMat,
            viewMat,
            worldMat,
            /*firstPass*/ true);
    }
}
Esempio n. 14
0
void ToolKillZone::glRenderAction(GLContextData& contextData) const
	{
	if(render)
		{
		/* Get pointer to context data item: */
		DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this);
		
		if(baseDevice!=0)
			{
			/* Go to base device's coordinate system: */
			glPushMatrix();
			glMultMatrix(baseDevice->getTransformation());
			}
		
		/* Check if the model display list is up-to-date: */
		if(modelVersion!=dataItem->modelVersion)
			{
			/* Update and render the kill zone model: */
			glNewList(dataItem->modelDisplayListId,GL_COMPILE_AND_EXECUTE);
			glMaterial(GLMaterialEnums::FRONT,material);
			renderModel();
			glEndList();
			dataItem->modelVersion=modelVersion;
			}
		else
			{
			/* Render the kill zone model from the display list: */
			glCallList(dataItem->modelDisplayListId);
			}
		
		if(baseDevice!=0)
			{
			/* Go back to physical coordinates: */
			glPopMatrix();
			}
		}
	}
Esempio n. 15
0
void copyChunk(Chunk *dest, Chunk *src) {
    Block *srcBlock, *destBlock;

    for (int x = 0; x < CHUNK_SIZE; x++) {
        for (int y = 0; y < CHUNK_SIZE; y++) {
            for (int z = 0; z < CHUNK_SIZE; z++) {
                srcBlock = getBlock(src, x, y, z);
                destBlock = getBlock(dest, x, y, z);

                destBlock->active = srcBlock->active;
                destBlock->color = srcBlock->color;

                if (destBlock->logic) {
                    free(destBlock->logic);
                    destBlock->logic = NULL;
                }

                if (destBlock->data) {
                    destBlock->data = NULL;
                }

                if (srcBlock->logic) {
                    destBlock->logic = calloc(1, sizeof(Logic));
                    memcpy(destBlock->logic, srcBlock->logic, sizeof(Logic));
                    updateLogicModel(destBlock);
                } else if (srcBlock->data) {
                    destBlock->data = createModel();
                    copyChunk(destBlock->data->chunk, srcBlock->data->chunk);
                    renderModel(destBlock->data);
                }
            }
        }
    }

    renderChunk(dest);
}
Esempio n. 16
0
void Viewer::onRender()
{
  static char s[40];

  // clear the vertex and face counters
  m_vertexCount = 0;
  m_faceCount = 0;


  // clear all the buffers
  g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
						D3DCOLOR_XRGB(0,0,77), 1.0f, 0 );
  // Setup Prespective matrix
  g_pD3DDevice->BeginScene();

  D3DXMATRIX matProj,matWorld,matView, matViewInv;
  D3DXMatrixPerspectiveFovRH( &matProj, D3DX_PI/4, (float)m_width / (float)m_height, m_scale * 50.0f, m_scale * 1000.0f );
  
  
  g_pD3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );
  
  D3DXMATRIX Mat1,Mat2;                // tmp matrix

  D3DXMatrixIdentity(&Mat1);

  

  D3DXMatrixTranslation(&Mat2,0.0f,0.0f,-m_distance * m_scale);
  
  D3DXMatrixMultiply(&Mat1,&Mat2,&Mat1);

  
  D3DXMatrixRotationX(&Mat2, m_tiltAngle/180.0f*3.14159f);
  D3DXMatrixMultiply(&Mat1,&Mat2,&Mat1);

  D3DXMatrixRotationZ(&Mat2, m_twistAngle/180.0f*3.14159f);
  D3DXMatrixMultiply(&Mat1,&Mat2,&Mat1);


  D3DXMatrixTranslation(&Mat2,0.0f,0.0f,-90.0f * m_scale);			//I have done à 1/1 translation
  D3DXMatrixMultiply(&matView,&Mat2,&Mat1);							//of the OpenGL version

  g_pD3DDevice->SetTransform( D3DTS_VIEW, &matView );

  D3DXMatrixIdentity(&matWorld);
  g_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld ); 

  // setup the light attributes
  D3DLIGHT9 light;
  ZeroMemory( &light, sizeof(D3DLIGHT9) );
  light.Type       = D3DLIGHT_DIRECTIONAL;
  light.Ambient.r=0.2f;light.Ambient.g=0.2f;light.Ambient.b=0.2f;light.Ambient.a=1.0f;
  light.Diffuse.r=1.0f;light.Diffuse.g=1.0f;light.Diffuse.b=1.0f;light.Diffuse.a=1.0f;
  light.Specular.r=0.1f;light.Specular.g=0.1f;light.Specular.b=0.1f;light.Specular.a=1.0f;
    
  //light.Direction= D3DXVECTOR3(0.0f,0.70f,0.70f);
  light.Direction= D3DXVECTOR3(sinf(Tick::getTick()/1000.0f),cosf(Tick::getTick()/1000.0f),-0.5f);

  float r=light.Direction.x*light.Direction.x
	  +light.Direction.y*light.Direction.y
	  +light.Direction.z*light.Direction.z;

  light.Direction.x/=r;
  light.Direction.y/=r;
  light.Direction.z/=r;  

  g_pD3DDevice->SetLight( 0, &light );
  g_pD3DDevice->LightEnable( 0, TRUE );  
  g_pD3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

  if(m_bBump)
  {
      g_pD3DDevice->SetVertexShaderConstantF(13, (float*)&light.Diffuse, 1 );
      g_pD3DDevice->SetVertexShaderConstantF(14, (float*)&light.Specular, 1 );
      g_pD3DDevice->SetVertexShaderConstantF(15, (float*)&light.Ambient, 1 );
      g_pD3DDevice->SetVertexShaderConstantF(16, (float*)&(-((D3DXVECTOR3)light.Direction)), 1 );

	  D3DXMatrixTranspose( &Mat1, &matWorld );
      g_pD3DDevice->SetVertexShaderConstantF( 0, (float*)&Mat1, 4 );

      D3DXMatrixMultiply( &Mat1, &matView, &matProj );
      D3DXMatrixMultiply( &Mat1, &matWorld, &Mat1 );
      D3DXMatrixTranspose( &Mat1, &Mat1 );
      g_pD3DDevice->SetVertexShaderConstantF( 4, (float*)&Mat1, 4 );

	  float Const[4] = {0.5f,0.5f,0.5f,0.5f};

      g_pD3DDevice->SetVertexShaderConstantF( 20,Const, 1 );
  }
  
  // render the model
  renderModel();

  g_pD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

  // render the cursor
  renderCursor();

  RECT FontPosition;

  FontPosition.top = 0;
  FontPosition.left = 0;
  FontPosition.right = m_width;
  FontPosition.bottom = 100;

  sprintf(s,"%d fps, press 'b' to toggle bump mapping",m_fps);

  // 
  //  There are changes here between Direct3D SDK 9 and Direct3D SDK 9 summer 2003 update
  //

  /* Original SDK

  m_pFont->Begin();										
  m_pFont->DrawText(s,-1,&FontPosition,DT_CENTER,0xffffffff);
  m_pFont->End();

  */


  ///* Update

  m_pFont->DrawText(NULL,s,-1,&FontPosition,DT_CENTER,0xffffffff);

  //*/


  g_pD3DDevice->EndScene();


  // swap the front- and back-buffer
  g_pD3DDevice->Present( NULL, NULL, NULL, NULL );  

  // increase frame counter
  m_fpsFrames++;

}
Esempio n. 17
0
int renderChunkWithMeshing(Chunk *chunk, GLfloat *points, GLfloat *normals, GLfloat *colors, vec3 offset, float scale) {
    float blockWidth = scale * BLOCK_WIDTH;

    Color *face[CHUNK_SIZE][CHUNK_SIZE];
    unsigned int axis1, axis2, axis3, w, h, i, j, k, points_index, pos[3], dir[3];
    int sign, empty, models;
    Block *voxel1, *voxel2;
    vec3 d_axis2, d_axis3, fpos;

    //Color covered; // placeholder value for covered faces

    vec3 color;
    GLuint indices[] = {0, 1, 2, 0, 2, 3, 0, 3, 2, 0, 2, 1};
    GLfloat verts[12];

    /*
        axis1 is our "working" axis. We look at both sides of each "slice" of the chunk
        along that axis, and determine whether each face is visible by checking
        the block in front of it. For each face that is visible, its color is
        added to the face array. Then we look at the face array and split it up
        into rectangles of the same color using a greedy algorithm. We draw each
        rectangle and then move on to the next axis.


        // ***** this is currently removed *****
        I also implemented (my own idea!) a system where if a block is covered,
        a placeholder value is inserted in the face array instead. Then, when
        calculating the rectangles, the placeholder value is treated as a solid
        block, except for the fact that a rectangle cannot start on a face with
        the placeholder value. This still prevents faces that are completely
        hidden from being drawn, but allows for rectangles to be combined under
        blocks that are hiding different colors. This should result in a strictly
        smaller number of rectangles being drawn, at near-zero cost :D
        The only drawback is that large rectangles that are mostly hidden may
        still be drawn. Everything will still look fine, but there is a little
        extra cost from drawing the overlapping triangles. My hope is that
        overall the scene will render even faster.
    */

    memset(face, 0, sizeof(face));

    points_index = 0;
    models = 0;

    for (axis1 = 0; axis1 < 3; axis1++) {
        axis2 = (axis1 + 1) % 3;
        axis3 = (axis1 + 2) % 3;

        dir[0] = dir[1] = dir[2] = 0;
        d_axis2[0] = d_axis2[1] = d_axis2[2] = 0;
        d_axis3[0] = d_axis3[1] = d_axis3[2] = 0;

        for (sign = -1; sign < 2; sign += 2) {
            dir[axis1] = sign;

            for (pos[axis1] = 0; pos[axis1] < CHUNK_SIZE; pos[axis1]++) {
                empty = 1;

                // generate the face array
                for (pos[axis2] = 0; pos[axis2] < CHUNK_SIZE; pos[axis2]++) {
                    for (pos[axis3] = 0; pos[axis3] < CHUNK_SIZE; pos[axis3]++) {
                        voxel1 = getBlock(chunk, pos[0], pos[1], pos[2]);
                        voxel2 = ((sign > 0) ? (pos[axis1] < CHUNK_SIZE - 1) : (pos[axis1] > 0)) ?
                                 getBlock(chunk, pos[0]+dir[0], pos[1]+dir[1], pos[2]+dir[2]) :
                                 NULL;

                        if (voxel1->active) {

                            // there's a block that is potentially drawable
                            empty = 0;

                            if (voxel1->data)
                                // there's a model in the chunk. These have to be
                                // handled separately, so we mark a boolean flag
                                // so that we know to go back and render them
                                models = 1;
                            else if (!voxel2 || !voxel2->active || voxel2->data)
                                face[pos[axis3]][pos[axis2]] = &voxel1->color;
                        }
                    }
                }

                // nothing to do here. Continue on.
                if (empty)
                    continue;

                /*puts("---------------");
                printf("____%c%c AXIS____\n", sign > 0 ? '+' : '-', (char[]){'X','Y','Z'}[axis1]);
                printf("___SLICE #%02d___\n", pos[axis1]);
                for (i = 0; i < CHUNK_SIZE; i++) {
                    for (j = 0; j < CHUNK_SIZE; j++) {
                        printf("%c ", face[j][i] ? '#' : ' ');
                    }
                    puts("");
                }
                puts("---------------\n");*/

                // cut the face up into rectangles and draw them
                for (j = 0; j < CHUNK_SIZE; j++) {
                    for (i = 0; i < CHUNK_SIZE;) {
                        w = 1;

                        if (face[j][i]) {

                            // get the width
                            while (
                                (i + w < CHUNK_SIZE) &&
                                (face[j][i + w]) &&
                                (face[j][i + w]->all == face[j][i]->all)
                            ) w++;

                            // get the height
                            for (h = 1; j + h < CHUNK_SIZE; h++) {

                                // we look at the next row, and make sure each
                                // block on the face is solid and the same color.
                                // if it's not, we break from the outer loop
                                for (k = 0; k < w; k++) {
                                    if ((face[j + h][i + k] == NULL) ||
                                        (face[j + h][i + k]->all != face[j][i]->all)
                                    ) goto done;
                                }
                            }
                            done:

                            // draw it

                            color[0] = (float)face[j][i]->r / 255.0;
                            color[1] = (float)face[j][i]->g / 255.0;
                            color[2] = (float)face[j][i]->b / 255.0;

                            fpos[axis1] = pos[axis1] * blockWidth + offset[axis1];
                            fpos[axis2] = i * blockWidth + offset[axis2];
                            fpos[axis3] = j * blockWidth + offset[axis3];

                            d_axis2[axis2] = w * blockWidth;
                            d_axis3[axis3] = h * blockWidth;

                            if (sign > 0) fpos[axis1] += blockWidth;

                            verts[ 0] = fpos[0];
                            verts[ 1] = fpos[1];
                            verts[ 2] = fpos[2];
                            verts[ 3] = fpos[0] + d_axis2[0];
                            verts[ 4] = fpos[1] + d_axis2[1];
                            verts[ 5] = fpos[2] + d_axis2[2];
                            verts[ 6] = fpos[0] + d_axis2[0] + d_axis3[0];
                            verts[ 7] = fpos[1] + d_axis2[1] + d_axis3[1];
                            verts[ 8] = fpos[2] + d_axis2[2] + d_axis3[2];
                            verts[ 9] = fpos[0] + d_axis3[0];
                            verts[10] = fpos[1] + d_axis3[1];
                            verts[11] = fpos[2] + d_axis3[2];

                            getFaceData(&points[points_index], verts, &indices[((sign < 0) ? 6 : 0)]);
                            getFaceData(&normals[points_index], &cubeNormals[(sign > 0) ? 5-axis1 : 2-axis1], zeroIndices);
                            getFaceData(&colors[points_index], color, zeroIndices);

                            points_index += 18;

                            // empty the face array wherever we rendered it
                            for(k = 0; k < h; k++) {
                                memset(&face[j + k][i], 0, w * sizeof(Color*));
                            }
                        }

                        i += w;
                    }
                }
            }
        }
    }

    if (models) {

        // there were models in the chunk. Render them
        for (pos[0] = 0; pos[0] < CHUNK_SIZE; pos[0]++) {
            for (pos[1] = 0; pos[1] < CHUNK_SIZE; pos[1]++) {
                for (pos[2] = 0; pos[2] < CHUNK_SIZE; pos[2]++) {
                    voxel1 = getBlock(chunk, pos[0], pos[1], pos[2]);

                    if (voxel1->active && voxel1->data) {
                        if (voxel1->data->chunk->needsUpdate) {
                            renderModel(voxel1->data);
                            voxel1->data->chunk->needsUpdate = 0;
                        }

                        if (voxel1->logic)
                            points_index += addRenderedModel(
                                    voxel1->data, &points[points_index], &normals[points_index], &colors[points_index], *voxel1->logic->rotationMatrix,
                                    (vec3){pos[0]*blockWidth + offset[0], pos[1]*blockWidth + offset[1], pos[2]*blockWidth + offset[2]},
                                    scale / CHUNK_SIZE
                                );
                        else
                            points_index += addRenderedModel(
                                    voxel1->data, &points[points_index], &normals[points_index], &colors[points_index], identityMatrix,
                                    (vec3){pos[0]*blockWidth + offset[0], pos[1]*blockWidth + offset[1], pos[2]*blockWidth + offset[2]},
                                    scale / CHUNK_SIZE
                                );
                    }
                }
            }
        }
    }

    return points_index;
}
Esempio n. 18
0
// returns the number of elements added to the arrays
int renderChunkToArrays(Chunk *chunk, GLfloat *points, GLfloat *normals, GLfloat *colors, vec3 offset, float scale) {
    float blockWidth = BLOCK_WIDTH * scale;

    Block *block;
    vec3 color;
    int x, y, z;
    float min_x, min_y, min_z, max_x, max_y, max_z;

    GLfloat cube_vertices[8 * 3];
    GLuint zeroIndices[] = {0, 0, 0, 0, 0, 0};

    int points_index = 0;

    for (x = 0; x < CHUNK_SIZE; x++) {
        min_x = x * blockWidth + offset[0];
        max_x = min_x + blockWidth;

        for (y = 0; y < CHUNK_SIZE; y++) {
            min_y = y * blockWidth + offset[1];
            max_y = min_y + blockWidth;

            for (z = 0; z < CHUNK_SIZE; z++) {
                min_z = z * blockWidth + offset[2];
                max_z = min_z + blockWidth;

                block = getBlock(chunk, x, y, z);

                if (!block->active) {
                    continue;
                }

                if (block->data) {
                    if (block->data->chunk->needsUpdate) {
                        renderModel(block->data);
                        block->data->chunk->needsUpdate = 0;
                    }

                    if (block->logic)
                        points_index += addRenderedModel(
                            block->data,
                            &points[points_index],
                            &normals[points_index],
                            &colors[points_index],
                            *block->logic->rotationMatrix,
                            (vec3){min_x, min_y, min_z},
                            scale / CHUNK_SIZE
                        );
                    else
                        points_index += addRenderedModel(
                            block->data,
                            &points[points_index],
                            &normals[points_index],
                            &colors[points_index],
                            identityMatrix,
                            (vec3){min_x, min_y, min_z},
                            scale / CHUNK_SIZE
                        );
                    continue;
                }

                cube_vertices[ 0] = min_x; cube_vertices[ 1] = min_y; cube_vertices[ 2] = min_z;
                cube_vertices[ 3] = min_x; cube_vertices[ 4] = min_y; cube_vertices[ 5] = max_z;
                cube_vertices[ 6] = min_x; cube_vertices[ 7] = max_y; cube_vertices[ 8] = min_z;
                cube_vertices[ 9] = min_x; cube_vertices[10] = max_y; cube_vertices[11] = max_z;
                cube_vertices[12] = max_x; cube_vertices[13] = min_y; cube_vertices[14] = min_z;
                cube_vertices[15] = max_x; cube_vertices[16] = min_y; cube_vertices[17] = max_z;
                cube_vertices[18] = max_x; cube_vertices[19] = max_y; cube_vertices[20] = min_z;
                cube_vertices[21] = max_x; cube_vertices[22] = max_y; cube_vertices[23] = max_z;

                color[0] = (float)block->color.r / 255.0;
                color[1] = (float)block->color.g / 255.0;
                color[2] = (float)block->color.b / 255.0;

                // check if each face is visible
                if (x == CHUNK_SIZE - 1 || !getBlock(chunk, x+1, y, z)->active || getBlock(chunk, x+1, y, z)->data) {
                    getFaceData(&points[points_index],     cube_vertices,      &cubeIndices[ 0]);
                    getFaceData(&normals[points_index],    &cubeNormals[5],    zeroIndices);
                    getFaceData(&colors[points_index],     color,              zeroIndices);
                    points_index += 6 * 3;
                }

                if (y == CHUNK_SIZE - 1 || !getBlock(chunk, x, y+1, z)->active || getBlock(chunk, x, y+1, z)->data) {
                    getFaceData(&points[points_index],     cube_vertices,      &cubeIndices[ 6]);
                    getFaceData(&normals[points_index],    &cubeNormals[4],    zeroIndices);
                    getFaceData(&colors[points_index],     color,              zeroIndices);
                    points_index += 6 * 3;
                }

                if (z == CHUNK_SIZE - 1 || !getBlock(chunk, x, y, z+1)->active || getBlock(chunk, x, y, z+1)->data) {
                    getFaceData(&points[points_index],     cube_vertices,      &cubeIndices[12]);
                    getFaceData(&normals[points_index],    &cubeNormals[3],    zeroIndices);
                    getFaceData(&colors[points_index],     color,              zeroIndices);
                    points_index += 6 * 3;
                }

                if (x == 0 || !getBlock(chunk, x-1, y, z)->active || getBlock(chunk, x-1, y, z)->data) {
                    getFaceData(&points[points_index],     cube_vertices,      &cubeIndices[18]);
                    getFaceData(&normals[points_index],    &cubeNormals[2],    zeroIndices);
                    getFaceData(&colors[points_index],     color,              zeroIndices);
                    points_index += 6 * 3;
                }

                if (y == 0 || !getBlock(chunk, x, y-1, z)->active || getBlock(chunk, x, y-1, z)->data) {
                    getFaceData(&points[points_index],     cube_vertices,      &cubeIndices[24]);
                    getFaceData(&normals[points_index],    &cubeNormals[1],    zeroIndices);
                    getFaceData(&colors[points_index],     color,              zeroIndices);
                    points_index += 6 * 3;
                }

                if (z == 0 || !getBlock(chunk, x, y, z-1)->active || getBlock(chunk, x, y, z-1)->data) {
                    getFaceData(&points[points_index],     cube_vertices,      &cubeIndices[30]);
                    getFaceData(&normals[points_index],    &cubeNormals[0],    zeroIndices);
                    getFaceData(&colors[points_index],     color,              zeroIndices);
                    points_index += 6 * 3;
                }
            }
        }
    }

    return points_index;
}
Esempio n. 19
0
    bool Animator::maySwitchToAnotherMenu()
    {
        // Exit
        if (key[KEY_ESC] || pArea->get_state("animator.b_close"))
            return true;

        bool need_refresh = sel_idx >= 0;
        if (amz != mouse_z)
        {
            zoom *= expf( (amz - mouse_z) * 0.1f );
            need_refresh = true;
        }

        if (key[KEY_R])
        {
            zoom = 0.1f;
            r1 = 0.0f, r2 = 0.0f, r3 = 0.0f;
            need_refresh = true;
        }

        if (key[KEY_X])
        {
            if (TA3D_SHIFT_PRESSED)
                r1 = 0.0f, r2 = -90.0f, r3 = 0.0f;
            else
                r1 = 0.0f, r2 = 90.0f, r3 = 0.0f;
            need_refresh = true;
        }

        if (key[KEY_Y])
        {
            if (TA3D_SHIFT_PRESSED)
                r1 = -90.0f, r2 = 0.0f, r3 = 0.0f;
            else
                r1 = 90.0f, r2 = 0.0f, r3 = 0.0f;
            need_refresh = true;
        }

        if (key[KEY_Z])
        {
            if (TA3D_SHIFT_PRESSED)
                r1 = 0.0f, r2 = 180.0f, r3 = 0.0f;
            else
                r1 = 0.0f, r2 = 0.0f, r3 = 0.0f;
            need_refresh = true;
        }

        if (pArea->is_mouse_over("animator.render"))
        {
            if ((amx != mouse_x || amy != mouse_y) && mouse_b == 2)
            {
                r2 += mouse_x - amx;
                r1 += mouse_y - amy;
                need_refresh = true;
            }
            need_refresh |= userInteraction();
        }

        if (need_refresh)
            renderModel();

        return false;
    }
/// <summary>
/// Can be called after begin scene has been called, it will render the model in the scene...
/// </summary>
void ModelImageSprite::renderModel(IGraphics *graphics, ModelAnimState &animation, bool interpolate)
{		
	renderModel(graphics, interpolate);
}
Esempio n. 21
0
void ModelRenderer::render(const glm::mat4& projectionMat, const glm::mat4& viewMat)
{
    program_.use();

    LandcellManager& landcellManager = Core::get().landcellManager();
    ObjectManager& objectManager = Core::get().objectManager();

    glm::vec3 cameraPosition = Core::get().camera().position();
    glUniform4f(program_.getUniform("cameraPosition"),
        static_cast<GLfloat>(cameraPosition.x),
        static_cast<GLfloat>(cameraPosition.y),
        static_cast<GLfloat>(cameraPosition.z), 1.0f);

    // first pass, render solid objects and collect objects that need depth sorting
    depthSortList_.clear();

    for(auto& pair : objectManager)
    {
        Object& object = *pair.second;

        if(!object.model())
        {
            continue;
        }

        int dx = object.landcellId().x() - landcellManager.center().x();
        int dy = object.landcellId().y() - landcellManager.center().y();

        glm::vec3 blockPosition{dx * Land::kBlockSize, dy * Land::kBlockSize, 0.0};

        glm::mat4 rotateMat = glm::mat4_cast(object.location().rotation);
        glm::mat4 translateMat = glm::translate(glm::mat4{}, blockPosition + object.location().position);
        glm::mat4 worldMat = translateMat * rotateMat;

        renderOne(object.model(), projectionMat, viewMat, worldMat);
    }

    for(auto& pair : landcellManager)
    {
        int dx = pair.first.x() - landcellManager.center().x();
        int dy = pair.first.y() - landcellManager.center().y();

        glm::mat4 blockTransform = glm::translate(glm::mat4{}, glm::vec3{dx * Land::kBlockSize, dy * Land::kBlockSize, 0.0});

        for(const StaticObject& staticObject : pair.second->staticObjects())
        {
            renderOne(staticObject.resource, projectionMat, viewMat, blockTransform * staticObject.transform);
        }
    }

    // second pass, sort and render objects that need depth sorting
    sort(depthSortList_.begin(), depthSortList_.end(), CompareByDepth{});

    for(const DepthSortedModel& depthSortedModel : depthSortList_)
    {
        renderModel(*depthSortedModel.model,
            projectionMat,
            viewMat,
            depthSortedModel.worldMat,
            /*firstPass*/ false);
    }
}
Esempio n. 22
0
void Viewer::onRender()
{
  static char s[20];

  // clear the vertex and face counters
  m_vertexCount = 0;
  m_faceCount = 0;


  // clear all the buffers
  g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
    D3DCOLOR_XRGB(0,0,77), 1.0f, 0 );
  // Setup Prespective matrix
  g_pD3DDevice->BeginScene();

  D3DXMATRIX matProj;

  D3DXMatrixPerspectiveFovRH( &matProj, D3DX_PI/4, (float) m_width / (float) m_height, m_scale * 50.0f, m_scale * 1000.0f );

  g_pD3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );

  // setup the light attributes
  D3DLIGHT9 light;
  ZeroMemory( &light, sizeof(D3DLIGHT9) );
  light.Type       = D3DLIGHT_DIRECTIONAL;
  light.Ambient.r=0.3f;light.Ambient.g=0.3f;light.Ambient.b=0.3f;light.Ambient.a=1.0f;
  light.Diffuse.r=0.9f;light.Diffuse.g=0.9f;light.Diffuse.b=0.9f;light.Diffuse.a=1.0f;
  light.Specular.r=0.1f;light.Specular.g=0.1f;light.Specular.b=0.1f;light.Specular.a=1.0f;

  light.Direction= D3DXVECTOR3(0.0f,0.70f,0.70f);

  g_pD3DDevice->SetLight( 0, &light );
  g_pD3DDevice->LightEnable( 0, TRUE );  
  g_pD3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE );


  D3DXMATRIX Mat1,Mat2;

  D3DXMatrixIdentity(&Mat1);

  D3DXMatrixTranslation(&Mat2,0.0f,0.0f,-m_distance * m_scale);

  D3DXMatrixMultiply(&Mat1,&Mat2,&Mat1);

  D3DXMatrixRotationX(&Mat2, m_tiltAngle/180.0f*3.14159f);
  D3DXMatrixMultiply(&Mat1,&Mat2,&Mat1);

  D3DXMatrixRotationZ(&Mat2, m_twistAngle/180.0f*3.14159f);
  D3DXMatrixMultiply(&Mat1,&Mat2,&Mat1);

  D3DXMatrixTranslation(&Mat2,0.0f,0.0f,-90.0f * m_scale);			//I have done à 1/1 translation
  D3DXMatrixMultiply(&Mat1,&Mat2,&Mat1);							//of the OpenGL version

  g_pD3DDevice->SetTransform( D3DTS_VIEW, &Mat1 );

  D3DXMatrixIdentity( &Mat1 );
  g_pD3DDevice->SetTransform( D3DTS_WORLD, &Mat1 );

  // render the model
  renderModel();

  g_pD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

  // render the cursor
  renderCursor();

  RECT FontPosition;

  FontPosition.top = 0;
  FontPosition.left = 0;
  FontPosition.right = 100;
  FontPosition.bottom = 100;

  sprintf(s,"%d",m_fps);

  // 
  //  There are changes here between Direct3D SDK 9 and Direct3D SDK 9 summer 2003 update
  //

  /* Original SDK

  m_pFont->Begin();										
  m_pFont->DrawText(s,-1,&FontPosition,DT_CENTER,0xffffffff);
  m_pFont->End();

  */


  ///* Update

  m_pFont->DrawText(NULL,s,-1,&FontPosition,DT_CENTER,0xffffffff);

  //*/


  g_pD3DDevice->EndScene();


  // swap the front- and back-buffer
  g_pD3DDevice->Present( NULL, NULL, NULL, NULL );  

  // increase frame counter
  m_fpsFrames++;

}
Esempio n. 23
0
/** Restore a model with an elliptical beam */
void ModelRenderer::Restore(double* imageData, size_t imageWidth, size_t imageHeight, const Model& model, long double beamMaj, long double beamMin, long double beamPA, long double startFrequency, long double endFrequency, PolarizationEnum polarization)
{
	ao::uvector<double> renderedWithoutBeam(imageWidth * imageHeight, 0.0);
	renderModel(renderedWithoutBeam.data(), imageWidth, imageHeight, model, startFrequency, endFrequency, polarization, true);
	Restore(imageData, renderedWithoutBeam.data(), imageWidth, imageHeight, beamMaj, beamMin, beamPA, _pixelScaleL, _pixelScaleM);
}
Esempio n. 24
0
void renderStudentScene(S_Renderer *pRenderer, S_Model *pModel)
{
    S_StudentRenderer * renderer = (S_StudentRenderer *) pRenderer;
    S_Frag * frag;
    S_RGBA resultColor;
    int x = 0;
    int y = 0;
    int i = 0;
    double transparency = 0.0;

    /* test existence frame bufferu a modelu */
    IZG_ASSERT(pModel && pRenderer);

    /* nastavit projekcni matici */
    trProjectionPerspective(pRenderer->camera_dist, pRenderer->frame_w, pRenderer->frame_h);

    /* vycistit model matici */
    trLoadIdentity();

    /* nejprve nastavime posuv cele sceny od/ke kamere */
    trTranslate(0.0, 0.0, pRenderer->scene_move_z);

    /* nejprve nastavime posuv cele sceny v rovine XY */
    trTranslate(pRenderer->scene_move_x, pRenderer->scene_move_y, 0.0);

    /* natoceni cele sceny - jen ve dvou smerech - mys je jen 2D... :( */
    trRotateX(pRenderer->scene_rot_x);
    trRotateY(pRenderer->scene_rot_y);

    ///////////////////////////////// cerveny kralik ///////////////////////////////////
    /* nastavime material */
    renMatAmbient(pRenderer, &MAT_RED_AMBIENT);
    renMatDiffuse(pRenderer, &MAT_RED_DIFFUSE);
    renMatSpecular(pRenderer, &MAT_RED_SPECULAR);

    /* nejprve nastavime posuv cele sceny v rovine XY */
    trTranslate(pRenderer->scene_move_x - 1.2, pRenderer->scene_move_y, 0.0);

    /* a vykreslime nas model */
    renderModel(pRenderer, pModel);

    ///////////////////////////////// zeleny kralik ///////////////////////////////////
    /* nastavime material */
    renMatAmbient(pRenderer, &MAT_STUD_AMBIENT);
    renMatDiffuse(pRenderer, &MAT_STUD_DIFFUSE);
    renMatSpecular(pRenderer, &MAT_STUD_SPECULAR);
	
    /* nejprve nastavime posuv cele sceny v rovine XY */
    trTranslate(pRenderer->scene_move_x + 2.4, pRenderer->scene_move_y, 0.0);

    /* a vykreslime nas model */
    renderModel(pRenderer, pModel);
    ///////////////////////////////////////////////////////////////////////////////////

    // vypocet barvy a jeji vykresleni
    for(x = 0; x < pRenderer->frame_h; x++)
    {
        for(y = 0; y < pRenderer->frame_w; y++)
        {
            // inicializace
            transparency = 1.0;
            resultColor.red = 0;
            resultColor.green = 0;
            resultColor.blue = 0;
            resultColor.alpha = 0;

            i = renderer->hBuffer[y * pRenderer->frame_w + x];
            if(i < 0) resultColor = COLOR_BLACK;

            // vypocet smichane barvy
            while(i >= 0)
            {
                frag = fragvecGetPtr(renderer->nBuffer, i);
                resultColor.blue += transparency * frag->color.blue;
                resultColor.red += transparency * frag->color.red;
                resultColor.green += transparency * frag->color.green;
                transparency *= (1.0 - (frag->color.alpha / 255.0));
                i = frag->next;
            }

            // vykresleni vypocteneho pixelu
            PIXEL(pRenderer, x, y) = resultColor;
        }
    }
}
Esempio n. 25
0
void mainDraw(int mode) {
#ifdef USE_GL
	if(mode == 2)
		g_driver->CopyBlockPhys((unsigned char *)screen, 0, 0, 320, 200);
#endif


	if(mode == 0) {
		//restoreDirtyRects();
	} else {
		genVar5 = 0;
		copyToScreen(aux2, screen);
	}

#ifdef USE_GL
	g_driver->startFrame();
#endif

	setClipSize(0, 0, 319, 199);
	genVar6 = 0;

#ifdef USE_GL
	g_driver->cleanScreenKeepZBuffer();
#endif

#ifdef INTERNAL_DEBUGGER
	if(backgroundMode == backgroundModeEnum_3D) {
		for(int i = 0; i < getNumberOfRoom(); i++) {
			drawHardCol(i);
			drawSceZone(i);
		}

		drawConverZones();
	}
#endif



#ifdef USE_GL
	g_driver->startModelRender();
#endif

	for(int i = 0; i < numActorInList; i++) {
		int currentDrawActor = sortedActorTable[i];
		actorStruct *actorPtr;

		actorPtr = &actorTable[currentDrawActor];

		//if(actorPtr->flags & 0x25)
		{
			actorPtr->flags &= 0xFFFB;

			if(actorPtr->flags & 0x20) {
				mainDrawSub2(currentDrawActor);
			} else {
				char *bodyPtr = listBody->get(actorPtr->bodyNum);

				if(listBody->getVar1()) {
					//          initAnimInBody(actorPtr->FRAME, HQR_Get(listAnim, actorPtr->ANIM), bodyPtr);
				}

				renderModel(actorPtr->worldX + actorPtr->modX, actorPtr->worldY + actorPtr->modY, actorPtr->worldZ + actorPtr->modZ,
				            actorPtr->alpha, actorPtr->beta, actorPtr->gamma, bodyPtr);


				if(actorPtr->animActionType && actorPtr->field_98 != -1) {
					getHotPoint(actorPtr->field_98, bodyPtr, &actorPtr->hotPoint);
				}

				///////////////////////////////////// DEBUG
#ifdef INTERNAL_DEBUGGER
				//  if(debuggerVar_drawModelZv)
				{
					if(backgroundMode == backgroundModeEnum_3D) {
						drawZv(actorPtr);
					}
				}
#endif
				/////////////////////////////////////
			}

			if(BBox3D1 < 0)
				BBox3D1 = 0;
			if(BBox3D3 > 319)
				BBox3D3 = 319;
			if(BBox3D2 < 0)
				BBox3D2 = 0;
			if(BBox3D4 > 199)
				BBox3D4 = 199;

			if(BBox3D1 <= 319 && BBox3D2 <= 199 && BBox3D3 >= 0 && BBox3D4 >= 0) { // is the character on screen ?
				if(g_fitd->getGameType() == GType_AITD1) {
					if(actorPtr->field_0 == CVars[getCVarsIdx(LIGHT_OBJECT)]) {
						mainVar3 = (BBox3D3 + BBox3D1) / 2;
						mainVar2 = (BBox3D4 + BBox3D2) / 2;
					}
				}

#ifdef INTERNAL_DEBUGGER
				if(backgroundMode == backgroundModeEnum_2D)
#endif
				{
					if(g_fitd->getGameType() == GType_AITD1)
						drawBgOverlay(actorPtr);
				}
				//addToRedrawBox();
			} else {
				actorPtr->field_1A = -1;
				actorPtr->field_18 = -1;
				actorPtr->field_16 = -1;
				actorPtr->field_14 = -1;
			}
		}
	}

#ifdef USE_GL
	g_driver->stopModelRender();
#endif

	if(drawTextOverlay()) {
		//addToRedrawBox();
	}

	if(!lightVar1) {
		if(mode) {
			if(mode != 2 || lightVar2) {
				//makeBlackPalette();
				flipScreen();
				make3dTatouUnk1(0x10, 0);
				lightVar2 = 0;
			} else {
				//flipScreen();
			}
		} else {
			//mainDrawSub1();
		}
	} else {
	}

#ifdef INTERNAL_DEBUGGER
	debugger_draw();
#endif

#ifdef USE_GL
	g_driver->stopFrame();
#endif

	flipScreen();
}
Esempio n. 26
0
// 描画関数
void Draw(void)
{
	// 画像バッファ作成
	IplImage *copyImage = cvCreateImage( cvSize(frameImage->width, frameImage->height), 8, 4 ); // RGBA の4バイト
	
	frameImage = cvQueryFrame( capture );

	cvFlip( frameImage, frameImage, 1);
	
	//if(!mode)frameImage = cvLoadImage( "view000.bmp" ); 
    


	if(0){
		// detect marker

		// detect action
		Mat frame(frameImage);
		pDetector->init(frame);

		// スティック検出
		vector<iVec2> act;
		pDetector->detectAction( act );

		{// 検出結果描画
			for( int i = 0; i < act.size(); i++ ){
				int x = act[i].x, y = act[i].y;
				line( frame, Point(x-15, y) , Point(x+15, y), Scalar(255, 255, 0), 4, CV_AA );
				line( frame, Point(x, y-15) , Point(x, y+15), Scalar(255, 255, 0), 4, CV_AA );
				circle( frame, Point(x, y), 20, Scalar(255, 255, 255), 2 );
			}
		}
		*frameImage = frame;



		// out sound
		if(act.size() > 0){
			pDrum->tataku(LOW_TOM_1);
		}
		

	}

	


	cvCvtColor(frameImage, copyImage, CV_BGR2RGBA ); // OpenGL用に画素の並びを変換
    cvFlip( copyImage, copyImage, 0 ); // OpenGLの原点に合わせて上下反転
	
	glMatrixMode(GL_MODELVIEW);

	glEnable( GL_DEPTH_TEST );		// 隠面処理の適用
	mySetLight();					// 光源の設定
	glEnable( GL_LIGHTING );		// 光源ON

	// OpenCV の画像データを描画(キャプチャした画像を背景として描画)
	glDrawPixels( copyImage->width, copyImage->height, GL_RGBA, GL_UNSIGNED_BYTE, copyImage->imageData );
	glClear( GL_DEPTH_BUFFER_BIT ); // デプスバッファのみをクリア



	{// renderModel
			// モデルの表示位置{ x, y, z, a }
			// 決め打ちで書いてるが実際はこの座標と角度をマーカーで取得したものにする!
			float sym_l[]   = {-200,    0, -500, 10};
			float drum_l2[] = {-150, -100, -450, 10};
			float drum_l1[] = { -50, -100, -400, 10};
			float drum_r1[] = {  50, -100, -400, 10};
			float drum_r2[] = { 150, -100, -450, 10};
			float sym_r[]   = { 200,    0, -500, 10};

			float *pDrumSet[100];
			{
				pDrumSet[0] = sym_l;
				pDrumSet[1] = drum_l2;
				pDrumSet[2] = drum_l1;
				pDrumSet[3] = drum_r1;
				pDrumSet[4] = drum_r2;
				pDrumSet[5] = sym_r;
			}
			
			Mat frame(frameImage);

		if(mode==0)
		{
			// マーカー検出モード
			pDetector->init(frame);
			pDetector->getMarkerPos();

			mrkPos = &pDetector->m_marker;
			for(int i = 0; i < mrkPos->size(); i++ ){
				pDrumSet[i][0] =  (*mrkPos)[i].pos.x;
				pDrumSet[i][1] =  (*mrkPos)[i].pos.y;
				pDrumSet[i][2] = -(*mrkPos)[i].pos.z;
				pDrumSet[i][3] =  (*mrkPos)[i].angle * 180/3.14;
			}	
			if( mrkPos->size() != 6 ){
				for(int i = 0; i < mrkPos->size(); i++ ){
					renderModel( drumL2Model,  drumActModel, pDrumSet[i][0], pDrumSet[i][1], pDrumSet[i][2], pDrumSet[i][3], 0 );
				}

			}
			else{
				renderModel( cymbalLModel, cymbalActModel, sym_l[0],   sym_l[1],   sym_l[2],   sym_l[3], actFlg[0] );
				renderModel( drumL2Model,  drumActModel, drum_l2[0], drum_l2[1], drum_l2[2], drum_l2[3], actFlg[1] );
				renderModel( drumL1Model,  drumActModel, drum_l1[0], drum_l1[1], drum_l1[2], drum_l1[3], actFlg[2] );
				renderModel( drumR1Model,  drumActModel, drum_r1[0], drum_r1[1], drum_r1[2], drum_r1[3], actFlg[3] );
				renderModel( drumR2Model,  drumActModel, drum_r2[0], drum_r2[1], drum_r2[2], drum_r2[3], actFlg[4] );
				renderModel( cymbalRModel, cymbalActModel, sym_r[0],   sym_r[1],   sym_r[2],   sym_r[3], actFlg[5] );
			}

		}else{
			pDetector->init(frame);
			vector<iVec2> dAction;

			pDetector->detectAction(dAction);

			for(int i = 0; i < dAction.size(); i++ ){
				int xPos = dAction[i].x;
				int yPos = dAction[i].y;
				int id;
				int maxDiff = 640;
				for( int j=0; j < 6;j++){
					int dX = ((*mrkPos)[j].center.x - xPos );
					int dY = ((*mrkPos)[j].center.y - yPos );
					double diff = sqrt((double)dX*dX+dY*dY);

					if( diff < maxDiff ){
						maxDiff = diff;
						id = j;
					}
				}
				if(maxDiff < 150)
				act.push_back(id);
			}

			for(int i = 0; i < act.size(); i++){
				int n = act[i];
				actFlg[n] = 1;
				switch(n){
					case 5:
					pDrum->tataku(OPEN_HIHAT);
					break;
					case 1:
					pDrum->tataku(HIGH_TOM_1);
					break;
					case 2:
					pDrum->tataku(LOW_TOM_1);
					break;
					case 3:
					pDrum->tataku(LOW_TOM_2);
					break;
					case 4:
					pDrum->tataku(MID_TOM_1);
					break;
					case 0:
					pDrum->tataku(CLOSED_HIHAT);
					break;
					default:
						break;

				}
			}


			for(int i = 0; i < 6; i++ ){
				pDrumSet[i][0] =  (*mrkPos)[i].pos.x;
				pDrumSet[i][1] =  (*mrkPos)[i].pos.y;
				pDrumSet[i][2] = -(*mrkPos)[i].pos.z;
				pDrumSet[i][3] =  (*mrkPos)[i].angle * 180/3.14;
			}
			// 叩かれたモデルのactFlgを1にして渡す(複数指定可)
			renderModel( cymbalLModel, cymbalActModel, sym_l[0],   sym_l[1],   sym_l[2],   sym_l[3], actFlg[0] );
			renderModel( drumL2Model,  drumActModel, drum_l2[0], drum_l2[1], drum_l2[2], drum_l2[3], actFlg[1] );
			renderModel( drumL1Model,  drumActModel, drum_l1[0], drum_l1[1], drum_l1[2], drum_l1[3], actFlg[2] );
			renderModel( drumR1Model,  drumActModel, drum_r1[0], drum_r1[1], drum_r1[2], drum_r1[3], actFlg[3] );
			renderModel( drumR2Model,  drumActModel, drum_r2[0], drum_r2[1], drum_r2[2], drum_r2[3], actFlg[4] );
			renderModel( cymbalRModel, cymbalActModel, sym_r[0],   sym_r[1],   sym_r[2],   sym_r[3], actFlg[5] );

			for(int i=0;i<6; i++) actFlg[i] = 0;
			act.clear();

		}
	}

	glutSwapBuffers();
	cvReleaseImage( &copyImage );
}