D3DXVECTOR3 TERRAIN::GetNormal(int x, int y) { //Neighboring map nodes (D, B, C, F, H, G) INTPOINT mp[] = {INTPOINT(x-1, y), INTPOINT(x, y-1), INTPOINT(x+1, y-1), INTPOINT(x+1, y), INTPOINT(x, y+1), INTPOINT(x-1, y+1)}; //if there's an invalid map node return (0, 1, 0) if(!Within(mp[0]) || !Within(mp[1]) || !Within(mp[2]) || !Within(mp[3]) || !Within(mp[4]) || !Within(mp[5])) return D3DXVECTOR3(0.0f, 1.0f, 0.0f); //Calculate the normals of the 6 neighboring planes D3DXVECTOR3 normal = D3DXVECTOR3(0.0f, 0.0f, 0.0f); for(int i=0;i<6;i++) { D3DXPLANE plane; D3DXPlaneFromPoints(&plane, &GetWorldPos(INTPOINT(x, y)), &GetWorldPos(mp[i]), &GetWorldPos(mp[(i + 1) % 6])); normal += D3DXVECTOR3(plane.a, plane.b, plane.c); } D3DXVec3Normalize(&normal, &normal); return normal; }
void View::GetLimits (FP& x1, FP& x2, FP& y1, FP& y2) { HDC hdc; RECT rect; POINT client; hdc = GetDC (hWnd); GetClientRect (hWnd, &rect); client.x = rect.right - rect.left; client.y = rect.bottom - rect.top; DPtoLP (hdc, &client, 1); ReleaseDC (hWnd, hdc); POINT p1,p2; p1.x = client.x * 0.125; p1.y = client.y * 0.125; GetWorldPos (p1, x1, y2); p2.x = client.x * 0.875; p2.y = client.y * 0.875; GetWorldPos (p2, x2, y1); }
Bool View::GetNearestPoint (PCURVE pCurve, POINT SPos, ULong& iPnt) { FP x,y; GetWorldPos (SPos, x, y); ULong n; FP min = 1e9; Bool lock = FALSE; for (n=0; n<pCurve->cPoints; n++) { FP dist = FSqrt (((x - pCurve->CurveData[n].index) * (x - pCurve->CurveData[n].index)) + ((y - pCurve->CurveData[n].value) * (y - pCurve->CurveData[n].value))); if (dist < min) { iPnt = n; lock = TRUE; min = dist; } } return lock; }
int Ghost::Update(int sur[4]) { vec3 a(mBehaviour->Update(sur, GetPositionPointer(), GetSpeed(), &mTargetPoint)); SetDirection(a); SetWorldPos(vec3(GetWorldPos() + mDirection * (GetSpeed()))); return 0; }
void ActionMenu::ConfirmAction() { m_bChoiceLocked = true; if (m_numChoices == 4) m_slider.SetOffScreenPos(Vector2f(static_cast<float>(GAME_SCREEN_WIDTH), GetWorldPos().y)); DismissMenu(); }
void TexturedLine::Render() { if(!lineTexture) return; Vect lineDir = (pointB-pointA).Norm(); float halfWidth = width*0.5f; Camera *viewCam = level->GetCurrentCamera(); Vect camPos = viewCam->GetWorldPos(); Vect crossLine; DepthWriteEnable(FALSE); EnableBlending(TRUE); if(lineTexture->HasAlpha()) BlendFunction(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA); else BlendFunction(GS_BLEND_ONE, GS_BLEND_ONE); LoadTexture(lineTexture); LoadDefault3DSampler(); MatrixPush(); MatrixTranslate(GetWorldPos()); MatrixRotate(GetWorldRot()); RenderStart(); Vect endAdjust = (lineDir*halfWidth); Vect backEnd = (pointA-endAdjust); Vect frontEnd = (pointB+endAdjust); Color(color); crossLine = (camPos-backEnd).Cross(lineDir).Norm() * halfWidth; Vertex(backEnd+crossLine); TexCoord(1.0f, 0.0f); Vertex(backEnd-crossLine); TexCoord(0.0f, 0.0f); crossLine = (camPos-pointA).Cross(lineDir).Norm() * halfWidth; Vertex(pointA+crossLine); TexCoord(1.0f, 0.5f); Vertex(pointA-crossLine); TexCoord(0.0f, 0.5f); crossLine = (camPos-pointB).Cross(lineDir).Norm() * halfWidth; Vertex(pointB+crossLine); TexCoord(1.0f, 0.5f); Vertex(pointB-crossLine); TexCoord(0.0f, 0.5f); crossLine = (camPos-frontEnd).Cross(lineDir).Norm() * halfWidth; Vertex(frontEnd+crossLine); TexCoord(1.0f, 1.0f); Vertex(frontEnd-crossLine); TexCoord(0.0f, 1.0f); RenderStop(GS_TRIANGLESTRIP); MatrixPop(); LoadTexture(NULL); }
void MeshEntity::ResetTransform() { traceInFast(MeshEntity::ResetTransform); Vect position = GetWorldPos()+adjustPos; Quat rotation = GetWorldRot()*adjustRot; transform.SetIdentity(); transform.Translate(position); transform.Rotate(rotation); invTransform = transform; invTransform.Transpose(); traceOutFast; }
vec2 Ghost::GetGridPos(){ vec3 pos(GetWorldPos()); vec2 returnv; if (floor(pos.x) == floor(pos.x+0.2)) returnv.x = floor(pos.x); else { returnv.x = floor(pos.x+1); } if (floor(pos.z) == floor(pos.z+0.2)) returnv.y = floor(pos.z); else { returnv.y = floor(pos.z+1); } return returnv; }
void ActionMenu::DoDraw(DrawMgr& drawMgr) { Vector2f pos = GetWorldPos(); if (m_numChoices == 2) { drawMgr.DrawQuad(m_choices[0].GetCurrentFrame(), pos, DrawSpace::Screen); pos.x = pos.x + TILE_WIDTH + (TILE_WIDTH/2); drawMgr.DrawQuad(m_choices[1].GetCurrentFrame(), pos, DrawSpace::Screen); } else if (m_numChoices == 4) { drawMgr.DrawQuad(m_choices[0].GetCurrentFrame(), Vector2f(pos.x + TILE_WIDTH, pos.y), DrawSpace::Screen); drawMgr.DrawQuad(m_choices[1].GetCurrentFrame(), Vector2f(pos.x + (TILE_WIDTH * 2), pos.y + (TILE_HEIGHT / 2)), DrawSpace::Screen); drawMgr.DrawQuad(m_choices[2].GetCurrentFrame(), Vector2f(pos.x + TILE_WIDTH, pos.y + TILE_HEIGHT), DrawSpace::Screen); drawMgr.DrawQuad(m_choices[3].GetCurrentFrame(), Vector2f(pos.x, pos.y + (TILE_HEIGHT / 2)), DrawSpace::Screen); } }
void ePhys_corkscrew::Finalize() { GetWorldPos(m_vPos); if(!m_pszTarget1 && !m_pszTarget2) // pokud jsou cile { ECON(MSG_CON_DEBUG, "Entity without joint targets!"); Kill(this); } // najdi ukazatele na entity - cily eBase* pEnt1 = g_pEntMgr->FindEntityByTargetname(m_pszTarget1); eBase* pEnt2 = g_pEntMgr->FindEntityByTargetname(m_pszTarget2); if(!pEnt1 && !pEnt2) // pokud jsou cile { ECON(MSG_CON_DEBUG, "Can't find joint targets!"); Kill(this); } // ziskej data entVal_t* pBody1=NULL; if(pEnt1) pBody1 = pEnt1->m_Data.GetValue("body"); entVal_t* pBody2=NULL; if(pEnt2) pBody2 = pEnt2->m_Data.GetValue("body"); if(!pBody1 && !pBody2) {Kill(this); return;} // nema co nastavovat // ziskej konkretni ukazatele IP3DRigidBody* m_pBody1 = NULL; IP3DRigidBody* m_pBody2 = NULL; if(pBody1) m_pBody1 = *(IP3DRigidBody**)pBody1->pValue; if(pBody2) m_pBody2 = *(IP3DRigidBody**)pBody2->pValue; if(!m_pBody1 && !m_pBody2) {Kill(this); return;} // oba nulove ukazatele // ok... vytvor omezeni if (!m_pBody1) // pokud je 1. NULL, musi byt nastaven jako child ten druhy g_pNewtonWorld->ConstraintCreateCorkscrew(&m_pJoint, m_vPos, m_vDir, m_pBody2, m_pBody1, m_fMaxForce); else // je to naopak nebo jsou to 2 platne telesa g_pNewtonWorld->ConstraintCreateCorkscrew(&m_pJoint, m_vPos, m_vDir, m_pBody1, m_pBody2, m_fMaxForce); if(!m_pJoint) Kill(this); }
void RotationManipulator::RenderScaled(const Vect &cameraDir, float scale) { traceInFast(RotationManipulator::RenderScaled); DWORD i; Shader *rotManipShader = GetVertexShader(TEXT("Editor:RotationManipulator.vShader")); LoadVertexShader(rotManipShader); LoadPixelShader(GetPixelShader(TEXT("Base:SolidColor.pShader"))); rotManipShader->SetVector(rotManipShader->GetParameter(2), cameraDir); MatrixPush(); MatrixTranslate(GetWorldPos()); MatrixScale(scale, scale, scale); for(i=0; i<3; i++) { Vect axisColor(0.0f, 0.0f, 0.0f); axisColor.ptr[i] = 1.0f; if(i == activeAxis) axisColor.Set(1.0f, 1.0f, 0.0f); else axisColor.ptr[i] = 1.0f; rotManipShader->SetVector(rotManipShader->GetParameter(1), axisColor); LoadVertexBuffer(axisBuffers[i]); LoadIndexBuffer(NULL); Draw(GS_LINESTRIP); } LoadVertexBuffer(NULL); //---------------------------------------------------- Shader *solidShader = GetVertexShader(TEXT("Base:SolidColor.vShader")); LoadVertexShader(solidShader); MatrixPush(); MatrixRotate(Quat().SetLookDirection(cameraDir)); LoadVertexBuffer(axisBuffers[2]); LoadIndexBuffer(NULL); solidShader->SetColor(solidShader->GetParameter(1), 0.5, 0.5, 0.5, 0.5); Draw(GS_LINESTRIP); MatrixScale(1.25f, 1.25f, 1.25f); //--------------- if(activeAxis == 4) solidShader->SetColor(solidShader->GetParameter(1), 1.0f, 1.0f, 0.0, 1.0f); else solidShader->SetColor(solidShader->GetParameter(1), 0.8, 0.8, 0.8, 0.8); Draw(GS_LINESTRIP); MatrixPop(); MatrixPop(); LoadVertexShader(NULL); LoadPixelShader(NULL); traceOutFast; }
void RotationManipulator::ProcessMouseRay(const Vect &cameraDir, float scale, const Vect &rayOrig, const Vect &rayDir) { traceIn(RotationManipulator::ProcessMouseRay); activeAxis = -1; curCameraDir = cameraDir; Matrix mat; mat.SetIdentity(); mat.Translate(GetWorldPos()); mat.Scale(scale, scale, scale); bManipulating = false; DWORD i,j; for(i=0; i<3; i++) { for(j=0; j<30; j++) { DWORD jp1 = (j == 29) ? 0 : j+1; Vect norm = axisNorms[i][j]; if(norm.Dot(cameraDir) > 0.01f) continue; Vect v1 = axisLines[i][j]; Vect v2 = axisLines[i][jp1]; v1.TransformPoint(mat); v2.TransformPoint(mat); Vect lineVec = (v2-v1); float lineLen = lineVec.Len(); Vect lineDir = lineVec*(1.0f/lineLen); float fT1, fT2; if(ClosestLinePoints(rayOrig, rayDir, v1, lineDir, fT1, fT2)) { if((fT2 < 0.0f) || (fT2 > lineLen)) continue; Vect closestPoint1 = rayOrig+(rayDir*fT1); Vect closestPoint2 = v1+(lineDir*fT2); if(closestPoint1.Dist(closestPoint2) < (0.4f*scale)) { Vect axis(0.0f, 0.0f, 0.0f); axis.ptr[i] = 1.0f; activeAxis = i; clickDir = cameraDir.Cross(axis.Cross(norm)).Cross(cameraDir).Norm(); clickOrig = closestPoint1; bManipulating = true; return; } } } } mat.SetIdentity(); mat.Translate(GetWorldPos()); mat.Rotate(Quat().SetLookDirection(cameraDir)); mat.Scale(scale*1.25f, scale*1.25f, scale*1.25f); for(j=0; j<30; j++) { DWORD jp1 = (j == 29) ? 0 : j+1; Vect norm = axisNorms[2][j]; Vect v1 = axisLines[2][j]; Vect v2 = axisLines[2][jp1]; v1.TransformPoint(mat); v2.TransformPoint(mat); norm.TransformVector(mat); Vect lineVec = (v2-v1); float lineLen = lineVec.Len(); Vect lineDir = lineVec*(1.0f/lineLen); float fT1, fT2; if(ClosestLinePoints(rayOrig, rayDir, v1, lineDir, fT1, fT2)) { if((fT2 < 0.0f) || (fT2 > lineLen)) continue; Vect closestPoint1 = rayOrig+(rayDir*fT1); Vect closestPoint2 = v1+(lineDir*fT2); if(closestPoint1.Dist(closestPoint2) < (0.6f*scale)) { activeAxis = 4; clickDir = cameraDir.Cross(norm); clickOrig = closestPoint1; curCameraDir = cameraDir; bManipulating = true; return; } } } traceOut; }
void MeshEntity::OnUpdatePosition() { traceInFast(MeshEntity::OnUpdatePosition); Super::OnUpdatePosition(); for(int i=0; i<MeshLights.Num(); i++) MeshLights[i].light->RemoveEntity(this, MeshLights[i].side); MeshLights.Clear(); List<LevelObject*> objects; level->GetObjects(bounds.GetTransformedBounds(transform), objects); for(int i=0; i<objects.Num(); i++) { LevelObject *levelObj = objects[i]; if(levelObj->type == ObjectType_Entity) { if(!levelObj->ent->IsOf(GetClass(Light))) continue; Light *light = (Light*)levelObj->ent; light->ProcessEntity(this); } } if(bStaticGeometry) return; Vect position = GetWorldPos()+adjustPos; Quat rotation = GetWorldRot()*adjustRot; Matrix transform; transform.SetIdentity(); transform.Rotate(rotation.GetInv()); transform.Translate(-position); SH.Clear(); level->GetSHIndirectLightSamples(GetWorldPos(), indirectLightDist, transform, SH); if(shadowDecal) { Vect shadowRot = -shadowDecal->shadowRot.GetDirectionVector(); Vect color(0.0f); if(SH.Num()) { color += Vect(SH[0]) * shadowRot.x; color += Vect(SH[1]) * shadowRot.y; color += Vect(SH[2]) * shadowRot.z; color += Vect(SH[3]) * fabsf(shadowRot.x); color += Vect(SH[4]) * fabsf(shadowRot.y); color += Vect(SH[5]) * fabsf(shadowRot.z); } else color = 0.3f; shadowDecal->decalColor = Vect4(color); shadowDecal->decalColor.w = (color.x+color.y+color.z)/3.0f; shadowDecal->decalColor.w = MIN(shadowDecal->decalColor.w*0.5f, 1.0f); shadowDecal->decalColor.w = 1.0f-(shadowDecal->decalColor.w*0.8f); } traceOutFast; }
void eInfo_ladder_point::Render(float deltaTime) { GetWorldPos(m_vPos); // je hrac pobliz nejakeho bodu? // UPD: FIXME: nezobrazovat // ikonu ak je kamera otocena smerom od ladderu // pridat premennu m_vPlayerRot, rovnako ako je m_vPlayerPos if ((fabs (m_vPlayerPos->x - m_vPos.x) < (bUp ? ACTIVE_LADDER_UP_DISTANCE_HOR : ACTIVE_LADDER_DISTANCE_HOR)) && \ (fabs (m_vPlayerPos->y - m_vPos.y) < ACTIVE_LADDER_DISTANCE_VER) && \ (fabs (m_vPlayerPos->z - m_vPos.z) < (bUp ? ACTIVE_LADDER_UP_DISTANCE_HOR : ACTIVE_LADDER_DISTANCE_HOR))) { if (m_nMoveState == MOVE_NONE) // jeste nepouzil zebrik { g_HUD.bDrawTexUse = true; // zjisti, zda byla stisknuta klavesa pouzit if(g_pInput->IsKeyDownFirstTime((int)CVk_use.GetFloat())) { //ECON(MSG_ERR, "ZACATEK POHYBU PO ZEBRIKU!!!!"); g_pCharCtrl->LadderBegin(m_vPos, 0.0f); // TODO: pouzit m_nAngle, jenze ono to nebude presne sedet. Nemuzu testovat, nemam zatim novy charctrl :) OnStartMove.RaiseEvent(this); m_nMoveState = MOVE_START; s_nActivatorID = m_nID; } } else if(m_nMoveState==MOVE_MOVE) // hrac se pohyboval po zebriku a dosahl poprve nejaky bod -> konec pohybu { //ECON(MSG_ERR, "KONEC POHYBU PO ZEBRIKU!!!!"); g_pCharCtrl->LadderEnd(!!bUp); OnEndMove.RaiseEvent(this); m_nMoveState = MOVE_NONE; // uz je vlastne zase mimo zebrik s_nActivatorID = 0; } // test, aby hrac nesel dolu mimo rozsah zebriku if (!bUp && m_vPlayerPos->y < m_vPos.y-2.0f) { //ECON(MSG_ERR, "KONEC POHYBU PO ZEBRIKU (TEST DN)!!!!"); g_pCharCtrl->LadderEnd(false); OnEndMove.RaiseEvent(this); m_nMoveState = MOVE_NONE; // uz je vlastne zase mimo zebrik s_nActivatorID = 0; } else if (bUp && m_vPlayerPos->y > m_vPos.y) // test, aby hrac nesel nahoru mimo rozsah zebriku { //ECON(MSG_ERR, "KONEC POHYBU PO ZEBRIKU (TEST UP)!!!!"); g_pCharCtrl->LadderEnd(true); OnEndMove.RaiseEvent(this); m_nMoveState = MOVE_NONE; // uz je vlastne zase mimo zebrik s_nActivatorID = 0; } } else // hrac je mimo bod zebriku { if(m_nMoveState==MOVE_START && s_nActivatorID == m_nID) m_nMoveState=MOVE_MOVE; // poprve opustil jeden z bodu, ted se bude pohybovat, dokud nedorazi na nejaky bod } }