const BOOLEAN CDrescher::PointInRolle(D3DVECTOR point,const float radius)const { point-=pos; D3DMATRIX m; { // Mähdrescher gemäß Steigung kippen D3DUtil_SetRotateYMatrix(m,-beta); D3DMath_VectorMatrixMultiply(point,point,m); D3DUtil_SetRotateXMatrix(m,-alpha); D3DMath_VectorMatrixMultiply(point,point,m); D3DUtil_SetRotateYMatrix(m,beta); D3DMath_VectorMatrixMultiply(point,point,m); } D3DUtil_SetRotateYMatrix(m,-ang.y); D3DMath_VectorMatrixMultiply(point,point,m); if (abs(point.x)>3.85f*0.5f+radius)return FALSE; if (abs(point.y)>0.85f*0.5f+radius)return FALSE; if (abs(point.z)>0.85f*0.5f+radius)return FALSE; return TRUE; }
void CGolfer::Throw() { CPlayer* p=(CPlayer*)parent; D3DMATRIX m; D3DVECTOR v=D3DVECTOR(0,0,2); D3DUtil_SetRotateYMatrix(m,-p->ang.y); D3DMath_VectorMatrixMultiply(v,v,m); pos=p->pos+v; if (!world->IsInside(pos))world->MakeInside(pos); pos.y=world->HeightAtPoint(pos.x,pos.z); box->SetPos(pos); CObject* akt=chain->GetFirst(); while (akt) { if (GetType(akt->id)==IDStall) { Rebound(((CStall*)akt)->box); Rebound(((CStall*)akt)->eingang); } if (GetType(akt->id)==IDTree) Rebound(((CTree*)akt)->box); if (GetType(akt->id)==IDDrescher) Rebound(((CDrescher*)akt)->box2); akt=akt->next; } schlag.phase=0.0f; parent=NULL; ejecttime=3.0f; }
CEi::CEi(const D3DVECTOR vpos,const D3DVECTOR vang,D3DVECTOR ospeed,const D3DVECTOR opos,const BOOLEAN relativespeed,const float vspeed,const UID vowner) :pos(vpos),ang(vang),speed(D3DVECTOR(0,0,vspeed)),owner(vowner),lpMesh(game->models->FindObject("Ei")) { D3DVECTOR v; D3DMATRIX m,m2; D3DUtil_SetRotateYMatrix(m,ang.y); if (!relativespeed)D3DMath_VectorMatrixMultiply(ospeed,ospeed,m); D3DUtil_SetRotateXMatrix(m2,-ang.x); D3DMath_MatrixMultiply(m,m2,m); D3DMath_VectorMatrixMultiply(v,D3DVECTOR(0,0,1)+opos,m); pos+=v; D3DMath_VectorMatrixMultiply(speed,speed,m); speed+=ospeed; speed.y+=ei_offsety; id=MakeUID(IDEi); }
const D3DVECTOR CDrescher::PrivotFromCenter2(const D3DVECTOR p)const { D3DMATRIX m; D3DUtil_SetRotateYMatrix(m,ang.y); D3DVECTOR v; D3DMath_VectorMatrixMultiply(v,D3DVECTOR(0,0,-1.186f),m); return p-v; }
const D3DVECTOR CDrescher::GetCenter2()const { D3DMATRIX m; D3DUtil_SetRotateYMatrix(m,ang.y); D3DVECTOR v; D3DMath_VectorMatrixMultiply(v,D3DVECTOR(0,0,-1.186f),m); return v+pos; }
void tCamera::RotateX(float angl){ // Стабилизирующая ф-ция инерции: //если угол вращения меньше шага вращения(погрешность) сбрасываем угол // if (fabsf(aX)<=stpnsX) aX=0.0f; // если камера не вращается,необходимо стабилизировать вращение //if (angl==0.0f) { // if (aX>0) aX-=stpnsX;//angl=-0.50f; // if (aX<0) aX+=stpnsX;//angl=+0.50f; //}else{ // if (angl<0) aX-=stpnsX*2.0f;//angl=-0.50f; // if (angl>0) aX+=stpnsX*2.0f;//angl=+0.50f; //} //if (aX>stpnsXmax) aX=stpnsXmax;// Verify Max //if (aX<-stpnsXmax) aX=-stpnsXmax;//Verify Min D3DXVECTOR3 right=D3DXVECTOR3(0,0,0); D3DXVec3Cross(&right,&objTest.up,&objTest.dir); D3DXMATRIX m1; D3DXMatrixIdentity(&m1); D3DXMatrixRotationAxis(&m1,&right,angl);//aX*fDeltaTime*1000.0f); D3DMath_VectorMatrixMultiply( objTest.dir,objTest.dir,m1); D3DMath_VectorMatrixMultiply( objTest.up,objTest.up,m1); }
void tCamera::RotateZ(float angl){ // пояснения см.в RotateX //if (fabsf(aZ)<=stpnsZ) aZ=0.0f; // //if (angl==0.0f) { // if (aZ>0) aZ-=stpnsZ;//angl=-0.50f; // if (aZ<0) aZ+=stpnsZ;//angl=+0.50f; //}else{ // if (angl<0) aZ-=stpnsZ*2.0f;//angl=-0.50f; // if (angl>0) aZ+=stpnsZ*2.0f;//angl=+0.50f; //} // //if (aZ>stpnsZmax) aZ=stpnsZmax;// Verify Max //if (aZ<-stpnsZmax) aZ=-stpnsZmax;//Verify Min D3DXVECTOR3 right=D3DXVECTOR3(0,0,0); D3DXVec3Cross(&right,&objTest.up,&objTest.dir); D3DXMATRIX m1; D3DXMatrixIdentity(&m1); D3DXMatrixRotationAxis(&m1,&objTest.dir,angl); D3DMath_VectorMatrixMultiply( right,right,m1); D3DMath_VectorMatrixMultiply( objTest.up,objTest.up,m1); }
void CDrescher::Unbind() { if (parent!=NULL) { CBauer* b=(CBauer*)parent; b->pos=pos; b->ang=ang; D3DMATRIX m; D3DVECTOR v=D3DVECTOR(0,0,-5.5f); D3DUtil_SetRotateYMatrix(m,b->ang.y); D3DMath_VectorMatrixMultiply(v,v,m); b->ang.y=-b->ang.y; b->pos+=v; b->object=NULL; } }
const D3DVECTOR CDrescher::GetOutput()const { D3DMATRIX m,matrix; D3DUtil_SetTranslateMatrix(matrix,pos); { // Mähdrescher gemäß Steigung kippen D3DUtil_SetRotateYMatrix(m,beta); D3DMath_MatrixMultiply(matrix,m,matrix); D3DUtil_SetRotateXMatrix(m,alpha); D3DMath_MatrixMultiply(matrix,m,matrix); D3DUtil_SetRotateYMatrix(m,-beta); D3DMath_MatrixMultiply(matrix,m,matrix); } D3DUtil_SetRotateYMatrix(m,ang.y); D3DMath_MatrixMultiply(matrix,m,matrix); D3DUtil_SetTranslateMatrix(m,D3DVECTOR(-1.48f,1.24f,-3.1f)); D3DMath_MatrixMultiply(matrix,m,matrix); if (schaukelphase>0.0f) { // schaukeln const float mittelpunkt=2.0f; D3DUtil_SetTranslateMatrix(m,0,0,-mittelpunkt); D3DMath_MatrixMultiply(matrix,m,matrix); D3DUtil_SetRotateXMatrix(m,schaukelwinkel()); D3DMath_MatrixMultiply(matrix,m,matrix); D3DUtil_SetTranslateMatrix(m,0,0,mittelpunkt); D3DMath_MatrixMultiply(matrix,m,matrix); } D3DVECTOR v; D3DMath_VectorMatrixMultiply(v,D3DVECTOR(0,0,0),matrix); return v; }
void pEngine::Rotatings(){ // напоминание: для правильной инерции obj->inertPrediction() должна вызываться всегда! std::list< boost::intrusive_ptr<tObj> >::const_iterator i,end; D3DXMATRIX m1; int debug=0; WaitForSingleObject(hObjList,INFINITE); for(i=objList.begin(),end=objList.end();i!=end;++i){ // if ((*i)->radius>50.0f) continue; int u=(*i)->GetUin(); if (u==41000){ debug=1; } (*i)->inertZ.InertPrediction();//предсказание-prediction.Необходимо задать obj->inert.Value // float zz=(*i)->inertZ.Value; D3DXMatrixIdentity(&m1); D3DXMatrixRotationAxis(&m1,&(*i)->tz,(*i)->inertZ.GetCurValue(fpDeltaTime)); D3DXMatrixMultiply(&(*i)->m,&(*i)->m,&m1); D3DMath_VectorMatrixMultiply( (*i)->tx,(*i)->tx,m1); D3DMath_VectorMatrixMultiply( (*i)->ty,(*i)->ty,m1); (*i)->inertX.InertPrediction(); D3DXMatrixIdentity(&m1); float ix=(*i)->inertX.GetCurValue(fpDeltaTime); if (ix!=0){ int debug=1; } D3DXMatrixRotationAxis(&m1,&(*i)->tx,ix); D3DXMatrixMultiply(&(*i)->m,&(*i)->m,&m1); D3DMath_VectorMatrixMultiply( (*i)->tz,(*i)->tz,m1); D3DMath_VectorMatrixMultiply( (*i)->ty,(*i)->ty,m1); (*i)->inertY.InertPrediction(); D3DXMatrixIdentity(&m1); D3DXMatrixRotationAxis(&m1,&(*i)->ty,(*i)->inertY.GetCurValue(fpDeltaTime)); D3DXMatrixMultiply(&(*i)->m,&(*i)->m,&m1); D3DMath_VectorMatrixMultiply( (*i)->tx,(*i)->tx,m1); D3DMath_VectorMatrixMultiply( (*i)->tz,(*i)->tz,m1); } if (debug==0){ bool error=1; } ReleaseMutex(hObjList); }
void CDrescher::Execute(float elapsed) { if (schaukelphase>0.0f) { schaukelphase-=(elapsed*12.0f); if (schaukelphase<0.0f)schaukelphase=0.0f; } if (IstNormale!=Normale) { // Den Mähdrescher "weich" an Untergrundsteigung anpassen GlattAnpassen(IstNormale.x,Normale.x,elapsed); GlattAnpassen(IstNormale.z,Normale.z,elapsed); // Y-Koordinate anpassen IstNormale.y=sqrtf(1-sqr(IstNormale.x)-sqr(IstNormale.z)); alpha=acosf(DotProduct(IstNormale,D3DVECTOR(0,1,0))); beta=atan2f(IstNormale.x,IstNormale.z); } if (parent!=NULL) { rolle+=elapsed*5.75f; D3DMATRIX m; D3DVECTOR v; D3DUtil_SetRotateYMatrix(m,ang.y); D3DMath_VectorMatrixMultiply(v,speed,m); pos+=(v*elapsed); pos.y=world->HeightAtPoint(pos.x,pos.z); float r=box1->GetRadius()*1.2f; D3DVECTOR c=GetCenter1(); c=korrigieren(c,D3DVECTOR(r,0,0)); c=korrigieren(c,D3DVECTOR(-r,0,0)); c=korrigieren(c,D3DVECTOR(0,0,r)); c=korrigieren(c,D3DVECTOR(0,0,-r)); pos=pos-GetCenter1()+c; UpdateBox(); speed+=(acc*elapsed); speed*=powf(0.45f,elapsed); const float s=sqrtf(sqr(speed.x)+sqr(speed.z)); if (rot!=0.0f) { float s2=sqrtf(s/5.0f); ang.y+=rot*s2*elapsed; } CPlayer* driver=(CPlayer*)parent; driver->pos=GetCenter1(); driver->ang=ang; driver->ang.y=-driver->ang.y; sound->SetFrequency(ULONG(20000.0f+s*3200.0f)); sound->Set3DParameters(pos); if (driver->IsLocal) { // An Objekten abprallen und Position senden CObject* o; o=chain->GetFirst(); while (o) { if (GetType(o->id)==IDTree) { CTree* t=(CTree*)o; if (t->box->Collidate(box2)) { pos=PrivotFromCenter2(box2->MoveOut(t->box)); UpdateBox(); goto weiter; } } if (GetType(o->id)==IDStall) { CStall* s=(CStall*)o; if (s->box->Collidate(box2)) { pos=PrivotFromCenter2(box2->MoveOut(s->box)); UpdateBox(); goto weiter; } } if ((o->IsType(IDDrescher))&&(o!=this)) { CDrescher* d=(CDrescher*)o; if (d->box2->Collidate(box2)) { pos=PrivotFromCenter2(box2->MoveOut(d->box2)); UpdateBox(); goto weiter; } } weiter: o=o->next; } struct _r { D3DVECTOR pos,ang,speed; }r; r.pos=pos; r.ang=ang; r.speed=speed; statusmessage->Send(DPID_ALLPLAYERS,NM_NOTIFY,id,1,0,0,&r,sizeof(r),FALSE); } }else rolle+=elapsed*0.7f; statusmessage->Execute(elapsed); // Kollisionen nur bei Server checken if (!game->IsServer)return; // Kollisionen mit Hühnern testen CObject* o=chain->GetFirst(); while (o) { if (GetType(o->id)==IDChicken) { CChicken* c=(CChicken*)o; if (c->dead!=0.0f)goto weiter2; // if (c->bound!=NULL)goto weiter2; if (parent!=NULL)if (HitRolle(c->box)) { // Getroffen schaukelphase=2*g_PI; c->Splat(SPLAT_NORMAL); ((CPlayer*)parent)->HasHit(c->id); ((CPlayer*)parent)->SendNotify(3,c->id); if (Config.blut)game->AddGimmick(new CDrescherBlood(id,1.5f)); if (Config.federn)game->AddGimmick(new CDrescherFedern(id,1.5f)); goto weiter2; } CBoundingTube* box=(parent?box1:box2); if (c->box->Collidate(box)) // Huhn nach ausserhalb bewegen { c->pos=c->box->MoveOut(box); goto weiter2; } } weiter2: o=o->next; } }
void CRadar::Update() { HDC dc; if (SUCCEEDED(lpSurface->GetDC(&dc))) { HBRUSH oldbrush; { // Löschen / Auf Farbe setzen PatBlt(dc,0,0,size,size,BLACKNESS); SelectObject(dc,GetStockObject(WHITE_PEN)); const HBRUSH green=CreateSolidBrush(RGB(0,64,0)); oldbrush=(HBRUSH)SelectObject(dc,green); Ellipse(dc,0,0,size,size); SelectObject(dc,oldbrush); DeleteObject(green); } const float sx=parent->pos.x,sy=parent->pos.z; const float mx=size/2.0f,my=size/2.0f; const float InvRation=1.0f/((0.4f)*(256.0f/float(size))); D3DMATRIX m; if (parent->IsType(IDChicken)) D3DUtil_SetRotateYMatrix(m,-parent->ang.y); else D3DUtil_SetRotateYMatrix(m,parent->ang.y); D3DVECTOR v; const HRGN rgn=CreateEllipticRgn(1,1,size-1,size-1); SelectClipRgn(dc,rgn); { // Begrenzung rendern D3DVECTOR b[4]={ D3DVECTOR(world->minx(),0,world->minz())-parent->pos, D3DVECTOR(world->maxx(),0,world->minz())-parent->pos, D3DVECTOR(world->maxx(),0,world->maxz())-parent->pos, D3DVECTOR(world->minx(),0,world->maxz())-parent->pos}; POINT p[4]; for (int i=0;i<4;i++) { D3DMath_VectorMatrixMultiply(b[i],b[i],m); b[i].x=b[i].x*InvRation+mx; b[i].z=-b[i].z*InvRation+my; p[i].x=(int)b[i].x; p[i].y=(int)b[i].z; } SelectObject(dc,GetStockObject(WHITE_PEN)); const HBRUSH green=CreateSolidBrush(RGB(0,128,0)); oldbrush=(HBRUSH)SelectObject(dc,green); Polygon(dc,&p[0],4); SelectObject(dc,oldbrush); DeleteObject(green); } // Grid rendern { D3DVECTOR v2; const HPEN pen1=CreatePen(PS_SOLID,1,RGB(0,192,0)),pen2=CreatePen(PS_SOLID,1,RGB(128,128,0)),pen3=CreatePen(PS_SOLID,1,RGB(0,128,128)),oldpen=(HPEN)SelectObject(dc,pen1); #define Grid 20 int ox=0,oy=0,oz=0,x,z; int num=int((size)/(Grid*InvRation))/2; if (parent->pos.x>0) while (ox<parent->pos.x)ox+=Grid; if (parent->pos.x<0) while (ox>parent->pos.x)ox-=Grid; if (parent->pos.z>0) while (oz<parent->pos.z)oz+=Grid; if (parent->pos.z<0) while (oz>parent->pos.z)oz-=Grid; if (TRUE) { // x/z SelectObject(dc,pen1); for (x=-num-1;x<=num+1;x++) // x-Achse { v.x=float(x*(Grid*InvRation))-(parent->pos.x*InvRation)+(ox*InvRation); v.y=0; v.z=size*0.5f; v2.x=float(x*(Grid*InvRation))-(parent->pos.x*InvRation)+(ox*InvRation); v2.y=0; v2.z=-int(size)*0.5f; D3DMath_VectorMatrixMultiply(v,v,m); D3DMath_VectorMatrixMultiply(v2,v2,m); MoveToEx(dc,int(mx+(v.x)),int(my+(-v.z)),NULL); LineTo(dc,int(mx+(v2.x)),int(my+(-v2.z))); } for (z=-num-1;z<=num+1;z++) // z-Achse { v.x=size*0.5f; v.y=0; v.z=float(z*(Grid*InvRation))-(parent->pos.z*InvRation)+(oz*InvRation); v2.x=-int(size)*0.5f; v2.y=0; v2.z=float(z*(Grid*InvRation))-(parent->pos.z*InvRation)+(oz*InvRation); D3DMath_VectorMatrixMultiply(v,v,m); D3DMath_VectorMatrixMultiply(v2,v2,m); MoveToEx(dc,int(mx+(v.x)),int(my+(-v.z)),NULL); LineTo(dc,int(mx+(v2.x)),int(my+(-v2.z))); } } SelectObject(dc,oldpen); ::DeleteObject(pen1); ::DeleteObject(pen2); ::DeleteObject(pen3); } // --- COLORREF c; float s,x,y; D3DVECTOR p; HBRUSH brush; // Objekte rendern CObject* akt=game->chain->GetFirst(); while (akt) { c=RGB(255,0,0); s=3; switch(GetType(akt->id)) { case IDChicken: if (((CChicken*)akt)->dead!=0.0f)goto weiter; p=((CChicken*)akt)->pos; c=RGB(255,255,255); s=3; break; case IDBauer: if (((CBauer*)akt)->dead!=0.0f)goto weiter; if (((CBauer*)akt)->HasObject(IDDrescher))goto weiter; p=((CBauer*)akt)->pos; c=RGB(192,128,0); s=5; break; case IDStall: p=((CStall*)akt)->pos; c=RGB(214,160,32); s=7; break; case IDTree: p=((CTree*)akt)->pos; c=RGB(0,230,0); s=4; break; case IDGartenkralle: p=((CGartenkralle*)akt)->pos; c=RGB(255,214,0); s=2; break; case IDDrescher: p=((CDrescher*)akt)->pos; c=RGB(255,0,0); s=7; break; case IDGolfer: p=((CGolfer*)akt)->pos; c=RGB(192,192,192); s=2; break; case IDPlasmaCannon: p=((CPlasmaCannon*)akt)->pos; c=RGB(255,255,0); s=3; break; default:goto weiter; } p=p-parent->pos; D3DMath_VectorMatrixMultiply(p,p,m); x=p.x*InvRation; y=-p.z*InvRation; if ((x)*(x)+(y)*(y)<((size*0.5f)*(size*0.5f))-(4.0f*4.0f*4.0f*4.0f)) { x+=mx; y+=my; SelectObject(dc,brush=CreateSolidBrush(c)); SelectObject(dc,GetStockObject(NULL_PEN)); Ellipse(dc,int(x-s),int(y-s),int(x+s),int(y+s)); SelectObject(dc,oldbrush); ::DeleteObject(brush); } weiter: akt=akt->next; } SelectObject(dc,GetStockObject(WHITE_PEN)); Line(dc,size/2,(size*10)/18,size/2,(size*8)/18); Line(dc,(size*10)/18,size/2,(size*8)/18,size/2); SelectClipRgn(dc,NULL); ::DeleteObject(rgn); lpSurface->ReleaseDC(dc); } MakeTransparent(lpSurface,FALSE); }