HelpWorld To Screen function, need help :(

Posts 1–4 of 4 · Page 1 of 1
World To Screen function, need help :(
Heres a video about what is happening:

W2S Function:
Code:
int screencenter[]= {Width /2, Height/2};
float fov[] = {(float)Width/90.0f, (float)Height/90.0f};
float* WorldToScreen(Vect3d &WorldLocation, Vect3d &mypos, Vect3d &viewAngles)
{
    Vect3d vLocal, vTransForm;
	vForward = new Vect3d();
	vRight = new Vect3d();
	vUpward = new Vect3d();

    AngleVectors(viewAngles);
    vLocal = SubVectorDist(WorldLocation, mypos);

    vTransForm.x = vLocal.dotproduct(*vRight);
    vTransForm.y = vLocal.dotproduct(*vUpward);
    vTransForm.z = vLocal.dotproduct(*vForward);

    if (vTransForm.z < 0.01)
        return false;

    float ScreenX = screencenter[0] + (screencenter[0] / vTransForm.z * (1 / fov[0])) * vTransForm.x;
    float ScreenY = screencenter[1] - (screencenter[1] / vTransForm.z * (1 / fov[1])) * vTransForm.y;
	float f [2] = {ScreenX, ScreenY};
	return f;
}
void AngleVectors(Vect3d viewAngles)
{
    float angle;
    float sr, sp, sy, cr, cp, cy, 
        cpi = (3.141f * 2 / 360);

    angle = viewAngles.y * cpi;
    //cpi = same view angles.x isn't

    sy = (float)sin(angle);
    cy = (float)cos(angle);
    angle = viewAngles.x * cpi;
    sp = (float)sin(angle);
    cp = (float)cos(angle);
    angle = viewAngles.z * cpi;
    sr = (float)sin(angle);
    cr = (float)cos(angle);

    vForward->x = cp * cy;
    vForward->y = cp * sy;
    vForward->z = -sp;


    vRight->x = (-1 * sr * sp * cy + -1 * cr * -sy);
    vRight->y = (-1 * sr * sp * sy + -1 * cr * cy);
    vRight->z = -1 * sr * cp;


    vUpward->x = (cr * sp * cy + -sr * -sy);
    vUpward->y = (cr * sp * sy + -sr * cy);
    vUpward->z = cr * cp;
}
bump (10 chars)
bump, please help.
bump :/xxxxx
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us