Exemplo n.º 1
0
const VCNIDrawable* VCNIComponent::ToDrawable() const
{
	VCN_ASSERT(IsDrawable());
	return dynamic_cast<const VCNIDrawable*>(this);;
}
void Chunk::Render(int mode, void *params)
{
    switch(mode)
    {
    case TOP_DOWN_LOW_RES:
    case TOP_DOWN_LOW_RES_HEIGHT:
    case TOP_DOWN_LOW_RES_LIGHT:
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    for (int y = 127; y >= 0; y--)
                    {
                        int id = blocks->content[y + z * 128 + x * 128 * 16];

                        if(IsDrawable(id))
                        {
                            switch(mode)
                            {
                            case TOP_DOWN_LOW_RES_HEIGHT:
                                img[x + z * 16] = Color(y / 127.0f * 255, y / 127.0f * 255, y / 127.0f * 255);
                                break;
                            case TOP_DOWN_LOW_RES:
                            case TOP_DOWN_LOW_RES_LIGHT:
                                img[x + z * 16] = GetBlockColor(id);
                                break;
                            }
                            break;
                        }
                    }
                }
            }
            break;
            
        case OPEN_GL_RENDER:
            for (int x = 0; x < 16; x++)
            {
                //glPushMatrix();
                
                //glTranslatef(x / 16.0f, 0, 0);
                
                for (int z = 0; z < 16; z++)
                {
                
                    //glPushMatrix();

                    //glTranslatef(0, 0, z / 16.0f);
                    
                    for (int y = 0; y < 128; y++)
                    {
                        int id = blocks->content[y + z * 128 + x * 128 * 16];

                        if(IsDrawable(id))
                        {
                            //glPushMatrix();
                            
                            //glTranslatef(0, y / 16.0f, 0);
                            //glTranslatef(1/32.0, 1/32.0, 1/32.0);
                            
                            DrawBlock(id);
                            
                            //glPopMatrix();
                        }
                    }
                    
                    //glPopMatrix();
                    
                }
                
                //glPopMatrix();
            }
            
         case CAVES_LOW_RES:
         case CAVES_LOW_RES_HEIGHT:
         case CAVES_LOW_RES_LIGHT:
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    img[x + z * 16] = Color(0, 0, 0, 0);

                    bool cave = false;
                    bool exit = false;
                    bool first = true;
                    bool bottom = false;
                    for (int y = 127; y >= 0; y--)
                    {
                        int id = blocks->content[y + z * 128 + x * 128 * 16];

                        if(IsDrawable(id))
                        {
                            if(first && !cave)
                                img[x + z * 16] = GetBlockColor(id);

                            first = false;

                            if(cave)
                                bottom = true;

                            if(id != 17 && id != 18)
                            {
                                cave = true;
                            }
                            else
                            {
                                cave = false;
                                bottom = false;
                            }
                        }

                        Color c;

                        float alpha = *((float*)params);

                        if(cave && id == 50)
                        {
                            c = img[x + z * 16];
                            Color c2 = GetBlockColor(id);
                            img[x + z * 16] = Color((int)(c2.r * (1 - alpha) + c.r * alpha), (int)(c2.g * (1 - alpha) + c.g * alpha), (int)(c2.b * (1 - alpha) + c.b * alpha));
                            break;
                        }
                        
                        if(cave && bottom)
                        {
                            switch(id)
                            {
                                case 0:
                                    c = img[x + z * 16];
                                    switch(mode)
                                    {
                                    case CAVES_LOW_RES_HEIGHT:
                                        img[x + z * 16] = Color((int)((y / 127.0f) * 256 * (1 - alpha) + c.r * alpha), (int)((y / 127.0f) * 265 * (1 - alpha) + c.g * alpha), (int)((y / 127.0f) * 256 * (1 - alpha) + c.b * alpha));
                                        break;
                                    case CAVES_LOW_RES:
                                    case CAVES_LOW_RES_LIGHT:
                                        img[x + z * 16] = Color((int)(c.r * alpha), (int)(c.g * alpha), (int)(c.b * alpha));
                                        break;
                                    }
                                    exit = true;
                                    break;
                                    
                                //case 8: //Water
                                //case 9: //Water moving
                                    //img[x + z * 16] = Color(38, 92, 255);
                                    //exit = true;
                                    break;

                                case 10: //Lava
                                case 11: //Lava Moving
                                    c = img[x + z * 16];
                                    img[x + z * 16] = Color((int)(198 * (1 - alpha) + c.r * alpha), (int)(58 * (1 - alpha) + c.g * alpha), (int)(4 * (1 - alpha) + c.b * alpha));
                                    exit = true;
                                    break;                              
                            }
                        }
                        
                        if(exit)
                            break;
                    }
                }
            }
            break;                       
        break;
    }
}