void CDR::update(NBEditor* editor, bool drag, rect<s32> offset)
{
	if (!editor->state->project) {
		return;
	}

	if (!editor->state->settings->getBool("always_show_position_handle") &&
			(editor->state->keys[KEY_LSHIFT] == EKS_UP) ==
			(type == CDR_XY || type == CDR_XZ || type == CDR_ZY)) {
		return;
	}

	Node* node = editor->state->project->GetCurrentNode();

	if (!node) {
		return;
	}

	NodeBox *box = node->GetCurrentNodeBox();

	if (!box) {
		return;
	}

	ISceneManager * smgr = editor->state->device->getSceneManager();

	if (drag) {
		// get mouse position
		position2di target = editor->state->mouse_position;
		target -= offset.UpperLeftCorner;

		// Get the ray
		line3d<irr::f32> ray = smgr->getSceneCollisionManager()
				->getRayFromScreenCoordinates(target, smgr->getActiveCamera());

		// Contains the output values
		vector3df wpos = vector3df(0, 0, 0); // The collision position

		// Not used, but required for function
		#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8
			const ISceneNode* tmpNode;
		#else
			ISceneNode* tmpNode;
		#endif
		triangle3df tmpTri;

		// Execute ray
		smgr->getSceneCollisionManager()->getCollisionPoint(ray,
				editor->state->plane_tri, wpos, tmpTri, tmpNode);

		// Snapping
		wpos -= vector3df(node->position.X, node->position.Y, node->position.Z);
		if (window == VIEW_XZ)
			wpos.Z -= 0.1;

		if (editor->state->settings->getBool("snapping")) {
			wpos.X = floor((wpos.X + 0.5) * 16 + 0.5) / 16 - 0.5;
			wpos.Y = floor((wpos.Y + 0.5) * 16 + 0.5) / 16 - 0.5;
			wpos.Z = floor((wpos.Z + 0.5) * 16 + 0.5) / 16 - 0.5;
		}

		// Do node limiting
		if (editor->state->settings->getBool("limiting")) {
			// X Axis
			if (wpos.X < -0.5) {
				wpos.X = -0.5;
			} else if (wpos.X > 0.5) {
				wpos.X = 0.5;
			}

			// Y Axis
			if (wpos.Y < -0.5) {
				wpos.Y = -0.5;
			} else if (wpos.Y > 0.5) {
				wpos.Y = 0.5;
			}

			// Z Axis
			if (wpos.Z < -0.5) {
				wpos.Z = -0.5;
			} else if (wpos.Z > 0.5) {
				wpos.Z = 0.5;
			}
		}

		// Call required function
		if (type < CDR_XZ) {
			box->resizeNodeBoxFace(editor->state, type, wpos,
				editor->state->keys[KEY_LCONTROL] == EKS_DOWN);
		} else {
			box->moveNodeBox(editor->state, type, wpos);
		}
		node->remesh();

		editor->triggerCDRmoved();
	}

	vector3df pos = box->GetCenter();

	switch (type) {
	case CDR_X_P:
		pos.X = box->two.X;
		break;
	case CDR_X_N:
		pos.X = box->one.X;
		break;
	case CDR_Y_P:
		pos.Y = box->two.Y;
		break;
	case CDR_Y_N:
		pos.Y = box->one.Y;
		break;
	case CDR_Z_P:
		pos.Z = box->two.Z;
		break;
	case CDR_Z_N:
		pos.Z = box->one.Z;
		break;
	default:
		break;
	}

	pos.X += node->position.X;
	pos.Y += node->position.Y;
	pos.Z += node->position.Z;

	vector2d<irr::s32> cpos = smgr->getSceneCollisionManager()
			->getScreenCoordinatesFrom3DPosition(
				pos,
				smgr->getActiveCamera()
	#if !(IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
				, true
	#endif
			);

	position = cpos + offset.UpperLeftCorner;
	visible = true;
}
示例#2
0
void CDR::update(NBEditor* editor,bool drag,rect<s32> offset){
	if (!editor->GetState()->project){
		printf("Project for NBEditor::updatePoint() not found!\n");
		return;
	}

	if (!editor->GetState()->Settings()->getSettingAsBool("always_show_position_handle")){
		if (editor->GetState()->keys[KEY_LSHIFT]==EKS_UP){
			if (type == CDR_XY || type == CDR_XZ || type == CDR_ZY){
				return;
			}
		}else{
			if (!(type == CDR_XY || type == CDR_XZ || type == CDR_ZY)){
				return;
			}
		}
	}

	Node* node = editor->GetState()->project->GetCurrentNode();

	if (!node)
		return;

	NodeBox* box = node->GetCurrentNodeBox();

	if (!box)
		return;

	if (drag){
			// get mouse position
			position2di target = editor->GetState()->mouse_position;
			target.X -= 5;
			target.Y -= 5;
			target -= offset.UpperLeftCorner;

			// get the ray
			line3d<irr::f32> ray = editor->GetState()->GetDevice()->getSceneManager()->getSceneCollisionManager()->getRayFromScreenCoordinates(target,editor->GetState()->GetDevice()->getSceneManager()->getActiveCamera());

			// contains the output values
			vector3df wpos = vector3df(0,0,0); // the collision position
			#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8
				const ISceneNode* tmpNode; // not needed, but required for function
			#else
				ISceneNode* tmpNode; // not needed, but required for function
			#endif
			triangle3df tmpTri; // not needed, but required for function

			// Execute ray
			editor->GetState()->GetDevice()->getSceneManager()->getSceneCollisionManager()->getCollisionPoint(ray,editor->GetState()->plane_tri,wpos,tmpTri,tmpNode);

			// Snapping
			wpos -= vector3df(node->getPosition().X,node->getPosition().Y,node->getPosition().Z);

			if (editor->GetState()->Settings()->getSettingAsBool("snapping")==true){
				for (int i=0;i<15;i++){
					if (wpos.X > editor->snappers[i]-0.0313 && wpos.X < editor->snappers[i]+0.0313){
						wpos.X = editor->snappers[i];
					}
					if (wpos.Y > editor->snappers[i]-0.0313 && wpos.Y < editor->snappers[i]+0.0313){
						wpos.Y = editor->snappers[i];
					}
					if (wpos.Z > editor->snappers[i]-0.0313 && wpos.Z < editor->snappers[i]+0.0313){
						wpos.Z = editor->snappers[i];
					}
				}
			}

			// Do node limiting
			if (editor->GetState()->Settings()->getSettingAsBool("limiting")==true){
				// X Axis
				if (wpos.X < -0.5)
					wpos.X = -0.5;
				else if (wpos.X > 0.5)
					wpos.X = 0.5;

				// Y Axis
				if (wpos.Y < -0.5)
					wpos.Y = -0.5;
				else if (wpos.Y > 0.5)
					wpos.Y = 0.5;

				// Z Axis
				if (wpos.Z < -0.5)
					wpos.Z = -0.5;
				else if (wpos.Z > 0.5)
					wpos.Z = 0.5;
			}
			
			// Call required function
			if (type < CDR_XZ){
				box->resizeNodeBoxFace(editor->GetState(),type,wpos,editor->GetState()->keys[KEY_LCONTROL]==EKS_DOWN);
			}else{
				box->moveNodeBox(editor->GetState(),type,wpos);
			}
			node->remesh();
	}

	vector3df pos;
	vector3df center = box->GetCenter();

	switch (type){
	case CDR_X_P:
		pos = center;
		pos.X = box->two.X;
		break;
	case CDR_X_N:
		pos = center;
		pos.X = box->one.X;
		break;
	case CDR_Y_P:
		pos = center;
		pos.Y = box->two.Y;
		break;
	case CDR_Y_N:
		pos = center;
		pos.Y = box->one.Y;
		break;
	case CDR_Z_P:
		pos = center;
		pos.Z = box->two.Z;
		break;
	case CDR_Z_N:
		pos = center;
		pos.Z = box->one.Z;
		break;
	case CDR_XZ:
		pos = center;
		break;
	case CDR_XY:
		pos = center;
		break;
	case CDR_ZY:
		pos = center;
		break;
	}

	pos.X+=node->getPosition().X;
	pos.Y+=node->getPosition().Y;
	pos.Z+=node->getPosition().Z;

	#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8
		vector2d<irr::s32> cpos = editor->GetState()->GetDevice()->getSceneManager()->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(pos,editor->GetState()->GetDevice()->getSceneManager()->getActiveCamera());
	#else
		vector2d<irr::s32> cpos = editor->GetState()->GetDevice()->getSceneManager()->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(pos,editor->GetState()->GetDevice()->getSceneManager()->getActiveCamera(),true);
	#endif

	position = cpos += offset.UpperLeftCorner;
	visible = true;
	return;
}