[ad_1]

I’ve OpenGL code for digicam:

static float  angleX = 180;
static float angleY = 0;

POINT mousexy;
GetCursorPos(&mousexy);

int xt=400; 
int yt=300;

angleX +=(xt - mousexy.x)/7.0f;
angleY +=(yt - mousexy.y)/7.0f;

if (angleY<-89.0){angleY=-89.0;}
if (angleY>89.0){angleY=89.0;}

SetCursorPos(xt,yt);       

static vector3 vPos = vector3( 25.0, 5.0, 5.0);

float PI = 3.1415926f;
float velocity = 25.0f;
float dx,dy,dz;
dx = dy = dz = 0.0f;

if(GetAsyncKeyState('W')& 0xFF00) 
    {
        dx =- sin(angleX/180*PI) * velocity; 
         dz =- cos(angleX/180*PI) * velocity;
    }

    if(GetAsyncKeyState('S')& 0xFF00) 
    {
        dx = sin(angleX/180*PI) * velocity;
         dz = cos(angleX/180*PI) * velocity;
    }

    if(GetAsyncKeyState('D')& 0xFF00) 
    {
        dx = sin((angleX+90)/180*PI) * velocity;   
         dz = cos((angleX+90)/180*PI) * velocity;
    }

    if(GetAsyncKeyState('A')& 0xFF00) 
    {
        dx = sin((angleX-90)/180*PI) * velocity;   
         dz = cos((angleX-90)/180*PI) * velocity;
    }
    

    vPos.x += dx*fElaspedAppTime;
    vPos.y += dy*fElaspedAppTime; 
    vPos.z += dz*fElaspedAppTime; 


    vector3 vLook;
    vLook.x = vPos.x - sin(angleX/180*PI);
    vLook.y = vPos.y + tan(angleY/180*PI);
    vLook.z = vPos.z - cos(angleX/180*PI);
    

    gluLookAt(vPos.x, vPos.y, vPos.z,
        vLook.x, vLook.y, vLook.z,
        0.0f, 1.0f, 0.0f);
    
    
    
    MeshManager.Draw_Mesh();

Code above works wonderful for OpenGL. I attempted to switch this code to my software program rendering undertaking (software program triangle rasterization, perspective appropriate texture mapping) however digicam isn’t woring correctly. That is my code from softrend undertaking (beneath):

matrix4x4 CMeshManager::Get_View_Matrix()
{
    float Time = Get_Elapsed_Time();

    UINT ScreenWidth = m_ViewWidth;
    UINT ScreenHeight = m_ViewHeight;

    POINT MousePos;
    GetCursorPos(&MousePos);
    
    SetCursorPos(ScreenWidth/2, ScreenHeight/2);
    
    static float DeltaX = 180;
    static float DeltaY = 0;

    DeltaX -=(( float(ScreenWidth/2)-MousePos.x) / 12.0f);
    DeltaY +=(( float(ScreenHeight/2)-MousePos.y) / 12.0f);

    float velocity = 25.0f;
    float dx,dy,dz;
    dx = dy = dz = 0.0f;

    if(GetAsyncKeyState('W')& 0xFF00) 
    {
        dx = -sin(DeltaX/180*PI) * velocity; 
         dz = -cos(DeltaX/180*PI) * velocity;

    
    }

    if(GetAsyncKeyState('S')& 0xFF00) 
    {
        dx = sin(DeltaX/180*PI) * velocity;
         dz = cos(DeltaX/180*PI) * velocity;

        
    }

    if(GetAsyncKeyState('D')& 0xFF00) 
    {
        dx = sin((DeltaX-90)/180*PI) * velocity;   
         dz = cos((DeltaX-90)/180*PI) * velocity;

    }

    if(GetAsyncKeyState('A')& 0xFF00) 
    {
        dx = sin((DeltaX+90)/180*PI) * velocity;   
         dz = cos((DeltaX+90)/180*PI) * velocity;
    }
    

    m_VecPos.x += dx * Time;
    m_VecPos.y += dy * Time; 
    m_VecPos.z += dz * Time; 

    m_VecLook.x = -sinf(DeltaX/180*PI);
    m_VecLook.y = tanf(DeltaY/180*PI);
    m_VecLook.z = -cosf(DeltaX/180*PI);


    m_VecLook = Vec3_Normalize(m_VecLook);
    m_VecUp = Vec3_Cross(m_VecLook,m_VecRight);
    m_VecUp = Vec3_Normalize(m_VecUp);
    m_VecRight = Vec3_Cross(m_VecUp,m_VecLook);
    m_VecRight = Vec3_Normalize(m_VecRight);
    
    float xp = -Vec3_Dot(m_VecPos, m_VecRight);
    float yp = -Vec3_Dot(m_VecPos, m_VecUp);
    float zp = -Vec3_Dot(m_VecPos, m_VecLook);

    matrix4x4 MatView = matrix4x4(
        m_VecRight.x, m_VecUp.x, m_VecLook.x, 0,
        m_VecRight.y, m_VecUp.y, m_VecLook.y, 0,
        m_VecRight.z, m_VecUp.z, m_VecLook.z, 0,
        xp,       yp,    zp,      1 );

    return MatView;
}

The place I’m mistaken?

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *