Ejemplo n.º 1
0
void MapBlock::QuadIntersectRay(const QuadTree::Node* node, const Ray& ray, float& tMin) const {
	if(!node->IsVisible()) return;
	if(!ray.IntersectsBox(node->mBoundingBox)) return;
	if(!node->mChildren[0]){
		GetPatchIntersect(node->mIndex, ray, tMin);
		return;
	}

	QuadIntersectRay(node->mChildren[0], ray, tMin);
	QuadIntersectRay(node->mChildren[1], ray, tMin);
	QuadIntersectRay(node->mChildren[2], ray, tMin);
	QuadIntersectRay(node->mChildren[3], ray, tMin);

	return;
}
Ejemplo n.º 2
0
void SceneManager::MouseMove(int x, int y, int /*flags*/){
	Vector2 wnd = Vector2(float(mWidth), float(mHeight));
	Vector3 mouse = Vector3(float(x), float(mHeight - y), 0.0f);

	mHoverEntity = 0;

	if(!mEntityFlag[ENTITY_CAN_HOVER_IDX].Size()) return;
	Array<Entity*, 10>& lst = mEntityFlag[ENTITY_CAN_HOVER_IDX];

	Ray ray = UnprojectRay(mouse, mCamera->GetTransform(), mCamera->GetProjection(), wnd);
	Vector3 camPos = mCamera->GetTransform().TransformCoord(Vector3(0.0f, 0.0f, 0.0f));
	float nearest = 9999.0f;
	float dist;
	for(unsigned int i = 0; i < lst.Size(); ++i){
		Entity* entity = lst[i];
		if(!entity->mVisible) continue;
		if(!ray.IntersectsBox(entity->GetBoundingBox(), dist)) continue;
		if(dist > nearest) continue;
		nearest = dist;
		mHoverEntity = entity;
	}
}
Ejemplo n.º 3
0
	virtual bool CastRay(const Ray& ray, Vector3& out, float maxLengthSq){
		if(!ray.IntersectsBox(mBoundingBoxTransformed)) return false;
		return true;
	}