void Ship::init(OglRenderer* renderer_) { fromFile("meshes/ship_.3ds", renderer_, 0); pos = firstPos; scale.x = scale.y = scale.z = 0.1; uint seed = chrono::high_resolution_clock::now( ).time_since_epoch( ).count( ); default_random_engine gen( seed ); uniform_real_distribution<double> dist( 0.0, 1.0 ); rot.x = 0; rot.y = 0; rot.z = 0; shRot.x = 0; shRot.y = 0; shRot.z = 0; roll = 0; speed = shipSpeed; sens = 200; vSpeed = 0; P = 0; autodrive = false; for ( uint i = 0; i < points; i++ ) { glm::vec3 rPoint(dist(gen)*rWi - rWi*0.5f, autodriveHeight*dist(gen), dist(gen)*rWi - rWi*0.5f); point.push_back(rPoint); } rotationMat = glm::mat4( 1 ); upV = glm::vec4( 0, 1, 0, 0 ); rightV = glm::vec4( 1, 0, 0, 0 ); vDir = glm::vec3( 0, 0, 0 ); }
float MapBlock::GetHeight(float x, float y) const { Vector3 mpos = mTransform.GetTranslate(); if(x < mpos.x) return 0.0f; if(y > mpos.y) return 0.0f; if(x > mpos.x + 160.0f) return 0.0f; if(y < mpos.y - 160.0f) return 0.0f; mpos.x = x - mpos.x; mpos.y = mpos.y - y; int ix = int(mpos.x / 2.5f) % 64; int iy = int(mpos.y / 2.5f) % 64; float tX = mpos.x - float(ix)*2.5f; float tY = mpos.y - float(iy)*2.5f; Vector3 rPoint(tX, tY, 100.0f); Vector3 v1(0.0f, 0.0f, mHeightmap->GetHeight(ix, iy)); Vector3 v2(2.5f, 0.0f, mHeightmap->GetHeight(ix+1,iy)); Vector3 v3(0.0f, 2.5f, mHeightmap->GetHeight(ix, iy+1)); float t; Ray ray(rPoint, Vector3(0.0f, 0.0f, -1.0f)); if(!ray.IntersectTriangle(v1, v2, v3, t)){ Vector3 v4(2.5f, 2.5f, mHeightmap->GetHeight(ix+1,iy+1)); if(!ray.IntersectTriangle(v2, v4, v3, t)) return 0.0f; } rPoint.z -= t; rPoint += mTransform.GetTranslate(); return rPoint.z; }
rSize ruiAbsoluteLayout::Layout(rRect& rect){ if (m_layoutItems.size() == 0) return rSize(0, 0); rPoint ptmin(INT32_MAX, INT32_MAX); rPoint ptmax(INT32_MIN, INT32_MIN); for (size_t i = 0; i < m_layoutItems.size(); i++){ ruiWidget* widget = m_layoutItems[i]; int margins[4] = { 0, 0, 0, 0 }; int top = 0; int left = 0; int bottom = 0; int right = 0; ruiStyle* properties = widget->ComputedStyle(); bool hasTop = properties->GetInt("top", top); bool hasLeft = properties->GetInt("left", left); bool hasBottom = properties->GetInt("bottom", bottom); bool hasRight = properties->GetInt("right", right); rSize itemSize = widget->Size(); rPoint position; if (hasTop) position.y = top; else if (hasBottom) position.y = rect.Bottom() - bottom - itemSize.y; else position.y = 0; if (hasLeft) position.x = left; else if (hasRight) position.x = rect.Right() - right - itemSize.x; else position.x = 0; widget->SetPosition(position); UpdatePoints(ptmin, ptmax, position); UpdatePoints(ptmin, ptmax, rPoint(position.x + itemSize.x, position.y + itemSize.y)); } rPoint difference = ptmax - ptmin; return rSize(difference.x, difference.y); }
bool MapBlock::CastRayDown(const Ray& ray, float& tMin) const { Vector3 mpos = mTransform.GetTranslate(); mpos.x = ray.mPoint.x - mpos.x; mpos.y = mpos.y - ray.mPoint.y; int ix = int(mpos.x / 2.5f) % 64; int iy = int(mpos.y / 2.5f) % 64; float tX = mpos.x - float(ix)*2.5f; float tY = mpos.y - float(iy)*2.5f; Vector3 v1(0.0f, 0.0f, mHeightmap->GetHeight(ix, iy)); Vector3 v2(2.5f, 0.0f, mHeightmap->GetHeight(ix+1,iy)); Vector3 v3(0.0f, 2.5f, mHeightmap->GetHeight(ix, iy+1)); Vector3 rPoint(tX, tY, ray.mPoint.z); Ray nRay = Ray(rPoint, ray.mDirection); if(!nRay.IntersectTriangle(v1, v2, v3, tMin)){ Vector3 v4(2.5f, 2.5f, mHeightmap->GetHeight(ix+1,iy+1)); if(!nRay.IntersectTriangle(v2, v4, v3, tMin)) return false; } return true; }