void CCamera::m_BuildWorldMatrix(void) { float4 sinx, cosx, siny, cosy, sinz, cosz; AD_Matrix pretrans, irot, swapXY; AD_Vect3D ptmp; sinx = fast_sinf(p_CurrentAngX); cosx = fast_cosf(p_CurrentAngX); siny = fast_sinf(p_CurrentAngY); cosy = fast_cosf(p_CurrentAngY); sinz = fast_sinf(p_CurrentAngZ); cosz = fast_cosf(p_CurrentAngZ); vect_neg(&p_CurrentPosition, &ptmp); mat_setmatrix_of_pretraslation(&pretrans, &ptmp); mat_identity(&p_CurrentRotationMatrix); p_CurrentRotationMatrix.a[0][0] = sinx * siny * sinz + cosx * cosz; p_CurrentRotationMatrix.a[0][1] = cosy * sinz; p_CurrentRotationMatrix.a[0][2] = sinx * cosz - cosx * siny * sinz; p_CurrentRotationMatrix.a[1][0] = sinx * siny * cosz - cosx * sinz; p_CurrentRotationMatrix.a[1][1] = cosy * cosz; p_CurrentRotationMatrix.a[1][2] = -cosx * siny * cosz - sinx * sinz; p_CurrentRotationMatrix.a[2][0] = -sinx * cosy; p_CurrentRotationMatrix.a[2][1] = siny; p_CurrentRotationMatrix.a[2][2] = cosx * cosy; mat_mul(&p_CurrentRotationMatrix, &pretrans, &p_ViewMatrix); // costruzione matrice inversa mat_transpose(&p_CurrentRotationMatrix, &irot); mat_setmatrix_of_pretraslation(&pretrans, &p_CurrentPosition); mat_mul(&pretrans, &irot, &p_InverseViewMatrix); // costruzione matrice per il linking con oggetti // 1) matrice di swap YZ mat_identity(&swapXY); swapXY.a[1][1]=0; swapXY.a[2][2]=0; swapXY.a[1][2]=1; swapXY.a[2][1]=-1; mat_mul(&p_InverseViewMatrix, &swapXY, &p_WorldMatrix); //mat_mul(&swapXY, &p_InverseViewMatrix, &p_WorldMatrix); //mat_copy(&p_InverseViewMatrix, &p_WorldMatrix); }
int32 CCamera::m_Init(void *arg1) { int32 res; float4 c, s; // faccio /2 cosi' a runtime si interpola direttamente // fov/2 (in radianti) if (p_FovTrack) { //for (int32 j=0; j<p_FovTrack->p_NumKeys; j++) // p_FovTrack->p_Keys[j].roll*=0.5f; } if (p_TargetTrack) if (!p_TargetTrack->m_Init(1)) return(0); if (p_RollTrack) if (!p_RollTrack->m_Init(1)) return(0); if (p_FovTrack) if (!p_FovTrack->m_Init(1)) return(0); // costruzione del frustrum (le normali puntano all'interno) s=fast_sinf(p_CurrentFov*0.5f); c=fast_cosf(p_CurrentFov*0.5f); vect_set(&p_LeftFrustrumNormal, c, 0, s); vect_set(&p_RightFrustrumNormal, -c, 0, s); vect_set(&p_UpFrustrumNormal, 0, c, s); vect_set(&p_DownFrustrumNormal, 0, -c, s); // si cerca l'ultima posizione (nella timeline) occupata da // una key; questo serve per il multicamera p_LastKeyPos=-1; if (p_PosTrack) if (p_PosTrack->p_Keys[p_PosTrack->p_NumKeys-1].posintrack > p_LastKeyPos) p_LastKeyPos=p_PosTrack->p_Keys[p_PosTrack->p_NumKeys-1].posintrack; if (p_TargetTrack) if (p_TargetTrack->p_Keys[p_TargetTrack->p_NumKeys-1].posintrack>p_LastKeyPos) p_LastKeyPos=p_TargetTrack->p_Keys[p_TargetTrack->p_NumKeys-1].posintrack; if (p_RollTrack) if (p_RollTrack->p_Keys[p_RollTrack->p_NumKeys-1].posintrack > p_LastKeyPos) p_LastKeyPos=p_RollTrack->p_Keys[p_RollTrack->p_NumKeys-1].posintrack; if (p_FovTrack) if (p_FovTrack->p_Keys[p_FovTrack->p_NumKeys-1].posintrack>p_LastKeyPos) p_LastKeyPos=p_FovTrack->p_Keys[p_FovTrack->p_NumKeys-1].posintrack; res=CGeometricObject::m_Init(arg1); // estraggo i dati al tempo 0 per un settaggio iniziale if (res) m_Update(0); return(res); }
void CFade2D::m_DoEfx2D(double pos) { FADE2DVERTEX *pVertices; float4 cpos; int32 intensity, color; HRESULT hr; D3DVIEWPORT8 vp; cpos=(float4)(3.141592*(pos-fstartpos)/(fendpos-fstartpos)); intensity=(int32)(-255.0f*fast_sinf(cpos)+255.0f); if (intensity<0) intensity=0; if (intensity>255) intensity=255; color=0xFF000000 | (intensity) | (intensity<<8) | (intensity<<16); p_RenderLib->p_Device->GetViewport(&vp); m_SetStages(); hr=p_VertexBuffer->Lock(0, 0, (BYTE**)&pVertices, D3DLOCK_DISCARD); // 0 --- 1 // | // 2 pVertices[0].p.x=0; pVertices[0].p.y=0; pVertices[0].p.z=0.5f; pVertices[0].w=2.0f; pVertices[0].color=color; pVertices[1].p.x=(float4)vp.Width; pVertices[1].p.y=0; pVertices[1].p.z=0.5f; pVertices[1].w=2.0f; pVertices[1].color=color; pVertices[2].p.x=(float4)vp.Width; pVertices[2].p.y=(float4)vp.Height; pVertices[2].p.z=0.5f; pVertices[2].w=2.0f; pVertices[2].color=color; // 5 // | // 4 --- 3 pVertices[3].p.x=(float4)vp.Width; pVertices[3].p.y=(float4)vp.Height; pVertices[3].p.z=0.5f; pVertices[3].w=2.0f; pVertices[3].color=color; pVertices[4].p.x=0; pVertices[4].p.y=(float4)vp.Height; pVertices[4].p.z=0.5f; pVertices[4].w=2.0f; pVertices[4].color=color; pVertices[5].p.x=0; pVertices[5].p.y=0; pVertices[5].p.z=0.5f; pVertices[5].w=2.0f; pVertices[5].color=color; hr=p_VertexBuffer->Unlock(); hr=p_RenderLib->p_Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); p_RenderLib->p_Device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); }
void CCamera::m_Update(float4 frame) { AD_Vect3D cameradir; const float4 EPS=0.2f; float4 focus, c, s; // estrazione dei dati tramite il keyframer, niente di piu' facile !!! if (p_PosTrack) p_PosTrack->m_GetData(frame, &p_CurrentPosition); if (p_TargetTrack) p_TargetTrack->m_GetData(frame, &p_CurrentTargetPosition); if (p_RollTrack) p_RollTrack->m_GetData(frame, &p_CurrentRoll); if (p_FovTrack) { p_FovTrack->m_GetData(frame, &p_CurrentFov); p_CurrentTanFov=(float4)tan(p_CurrentFov); // costruzione del frustrum (le normali puntano all'interno) s=fast_sinf(p_CurrentFov*0.5f); c=fast_cosf(p_CurrentFov*0.5f); vect_set(&p_LeftFrustrumNormal, c, 0, s); vect_set(&p_RightFrustrumNormal, -c, 0, s); vect_set(&p_UpFrustrumNormal, 0, c, s); vect_set(&p_DownFrustrumNormal, 0, -c, s); } vect_sub(&p_CurrentTargetPosition, &p_CurrentPosition, &cameradir); focus=vect_length(&cameradir); /* cr=currentroll; vect_set(&up, (float)sin(cr), (float)(-cos(cr)), 0.0); vect_cross(&cameradir, &up, &right); vect_normalize(&right); vect_cross(&right, &cameradir, &up); mat_insert_row(¤tmatrix_rot, 0, &right); mat_insert_row(¤tmatrix_rot, 1, &up); mat_insert_row(¤tmatrix_rot, 2, &cameradir); mat_mul(¤tmatrix_rot, &pretrans, ¤tmatrix); */ /* vect_normalize(&cameradir, &ptmp); if (fabs(ptmp.z) < EPS) { int32 fdfd=0; //if (cameradir.x >= 0) ax=0; az=0; ay=0; //else //ax=-1.5708f; } else*/ { p_CurrentAngX = (float4)-atan2 (cameradir.x, cameradir.z); p_CurrentAngY = (float4)asin (cameradir.y / focus); p_CurrentAngZ = -p_CurrentRoll; } m_BuildWorldMatrix(); }
/* returns -cos(x)*.5+.5 */ inline vec_float4 mcos(vec_float4 x) { const vec_float4 half = spu_splats(.5f); return fast_sinf(x + spu_splats(1.5f)) * half + half; }