Jump to content

  • Log In with Google      Sign In   
  • Create Account

adrian_134

Member Since 14 Jan 2012
Offline Last Active Oct 13 2013 08:24 AM

Topics I've Started

How can i calculate camera position

13 October 2013 - 06:57 AM

Hi!

 

I have one problem with my camera in 2D game, my camera look like this: http://www.coubetech.republika.pl/test/main.html camera tarack one obiect but camera can move only when is near game border, and i don't know how i can calculate camera position something obiect allowing of this game border. Now i try do this that:

var value = pos_obj.x - widthGame / 2;
        if (value < 0) value = 0;
        if (value > widthGame / 2) value = widthGame / 2;

But it's dosen't work very good;

My camera code:

var border = 150; 
if (g_CameraX > pos_obj.x - border) g_CameraX = pos_obj.x - border;
    if (g_CameraX < pos_obj.x + border - 640) g_CameraX = pos_obj.x + border - 640;
    if (g_CameraX < 0) g_CameraX = 0;
    if (g_CameraX > 1100 - 640) g_CameraX = 1100 - 640;

Select - a few question

08 July 2013 - 11:02 AM

Hi!

 

I have a few questions about select function, i wrote this code:

void TCPSerwer::sel()
    {
        struct timeval tv = {1, 0};
        fd_set temp_list = m_RecvList;
        //if(select(m_fdmax + 1, &temp_list, NULL, NULL, &tv) == SOCKET_ERROR)
        if(select(0, &temp_list, NULL, NULL, &tv) == SOCKET_ERROR)
        {
            perror( "select" );
            exit( 1 );
        }
        
        for(int i = 0; i <= m_fdmax; i++ )
        {
            if(FD_ISSET(i, &temp_list))
            {
                // New connection
                if(i == m_ListenSocket)
                {
                    acceptClient();
                }

                // Data from client
                else
                {
                    PacketHeader header;
                    int nbytes = recv(i, (char*)(&header), sizeof(PacketHeader),

                    // Error
                    if(nbytes < 0)
                    {
                        disconnectClient(i);
                    }
                    // success
                    else
                    {
                        std::cout << "type: " << header.type << "   len: " << header.length << std::endl;
                    }
                }
            }
        }
    }

I can give first arg to select function and i can don't do that, but why ? Why a should give first arg to select ? m_fdmax is highest number of socket, but this code working without this arg.

Next question is, why select need timeout ? When i don't give this arg select marks all socket as socket that can be readable but select doing this when socket haven't any data to read. When i give this arg i don't have this problem. But why ?

 

if m_fdmax is highest number of socket, i have to find next highest number of socket when i close connection, Right ? And i should doing this that:

int size = m_ClientVector.size();
for(int i = 0; i < size; i++)
{
       if(m_ClientVector[i] > m_fdmax)
               m_fdmax = m_ClientVector[i];
}

DirectWrite and DirectX 11

29 June 2013 - 07:59 AM

Hi!

 

How i can connect DirectWrite and DirectX 11, I want to render text to directx surface and use this texture as bitmap font ? I can't find  any tutorial about this. I must draw text in WM_PAINT message but is this only one way to do this ?


Android Intent - How can i open file

20 June 2012 - 01:53 AM

Hello!

To open image or sound we can use this code:
public String getExt(String filename){
      
   int dotIndex = 0;
   for(int i = filename.length()-1; i >= 0; i--)
   {
      if(filename.charAt(i) == '.') {
         dotIndex = i;
         break;
      }
   }
      
   return filename.substring(dotIndex + 1, filename.length());
}
   
public String getTypeAction(String s) {
      
   int slashIndex = 0;
   for(int i = 0; i < s.length(); i++)
   {
      if(s.charAt(i) == '/') {
         slashIndex = i;
         break;
      }
   }
      
   return s.substring(0, slashIndex);
}
//////
//////

MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext = getExt(file_to_action.getName());
ext = ext.toLowerCase();

String type = mime.getMimeTypeFromExtension(ext);

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file_to_action), getTypeAction(type) + "/*" );
startActivity(intent);

But the problem is when i want to open any different file for example: .mhtml, .bak. apk. When i do this my application is crash. I don't know where is the problem, i have application for .mhtml, .odt extenio but my application can't use this applications to open the file.
How i can open all file format or how i can check avaliable application for any file format ?

LUT texture for procedural terrain textring

06 February 2012 - 02:09 PM

Hi!

I create lut texture for precedural terrain texturing, that texture have the same size what my heightmap, because i want to store texture id in each pixel for one vertex, for example pixel[0, 1] store texture id for vertex[0, 1]. But i have problem when i try read texture id in pixel shader.

LUT texture is D3DFMT_A8R8G8B8.

That is code who save data to lut texture:
int getTextureID(D3DXVECTOR3 n)
{
    D3DXVECTOR3 nn;
    D3DXVec3Normalize(&nn, &n);
    if(nn.y <= 0.9f)
    {
        return 10;
    }
    return 0;
}

///
void generateTerrainVertex()
{
    D3DXVECTOR3 p(0.0f, 0.0f, 0.0f);
    int c = 0;
    for(int i = 0; i < cWidth; i++)
    {
        p.z = -(float)i * 2.0f);
   	 for(int j = 0; j < cHeight; j++)
        {
            p.x = (float)j * 2.0f;

            p.y = cHeightMap[getVertex(i, j)];
            v[c].pos    = p;
            v[c].normal = calcNormal(i, j);
            v[c].texcoord.x = (float)i / (float)cLUT->getWidth();
            v[c].texcoord.y = (float)j / (float)cLUT->getHeight();


	 	 // LUT Texture

            int id = getTextureID(v[c].normal);
       	 data[i + j * cLUT->getWidth()] = (id<<16) | (0<<8) | 0;

            c++;
   	 }
    }
}
The code is very simple because i want to lern this technique...

In my pixel shader i read texure id:
float3 Color = c0;

float3 B = tex2D(lutSampler, input.nonTiledTexCoord).rgb;
int texID = int(B.r);
if(texID == 10)
{
    Color =  c1;
}
"texID == 10" is false, i don't know why, why texID isn't 10 ? When i generated vertex i saved to lut texture 10 or 0, in pixel shader i have unknown value... Why ?
When i change the code:
float3 Color = c0;
float3 B = tex2D(lutSampler, input.nonTiledTexCoord).rgb;
if(B.r >= 0.01f)
{ Color =  c1;}
And i get this:
http://www.coubetech.republika.pl/p.jpg
The result is correctly but why b.r have unknown value ?

c0 - grass
c1 - stone

PARTNERS