Jump to content

camera pick is not working correctly.


ghoflvhxj
 Share

Recommended Posts

It would be a lot easier if we had code to review and try for ourselves. The video is nice as it shows what the effects of the issue but doesn't help us see what you are doing wrong. Show us your pick code. Or better yet, make a small example map and available code that we can easily try. 

 

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

On 5/2/2018 at 11:38 AM, macklebee said:

It would be a lot easier if we had code to review and try for ourselves. The video is nice as it shows what the effects of the issue but doesn't help us see what you are doing wrong. Show us your pick code. Or better yet, make a small example map and available code that we can easily try. 

 

ok, here is my code.

bool Player::Pick()
{
	//if player grab the entity, return true.
	if (pick_state == PICK_UP)
		return true;

	pick_state = PICK_EMPTY;
	pick_image = nullptr;

	if (!camera->Pick(context_halfwidth, context_halfheight, pickinfo))
		return false;

	pick = pickinfo.GetEntity();

	std::cout << pick->GetClassNameA() << " " << classname << std::endl;
	std::cout << pick->GetPhysicsMode() << " " << physics << std::endl;
	std::cout << pick->GetCollisionType() << " " << collision << std::endl;
  
  	if (window->KeyDown(Leadwerks::Key::R))
	{
		Leadwerks::Vec3 a = Leadwerks::Transform::Point(pickinfo.position, pick, nullptr);
		t->SetPosition(a);
	}
	
	//Check classname, physicsmode, collisiontype
	if (pick->GetClassNameA() != "Model" || pick->GetPhysicsMode() != Leadwerks::Entity::RigidBodyPhysics || pick->GetCollisionType() != Leadwerks::Collision::Prop)
		return false;

	//Check distance and mass
	if (pick->GetDistance(character) > pick_distance_limit || pick->GetMass() > pick_mass_limit)
		return false;
	
	pick_state = PICK_PICK;
	pick_image = hand_pick;
	return true;
}
void Player::PickUp()
{
	//Check distance
	if (pick->GetDistance(character) > pick_distance_limit)
	{
		PickInit();
		return;
	}

	//if the entity's first pick 
	if (pick_state == PICK_PICK)
	{
		pick_mass = pick->GetMass();

		//Transformation of the pick position from localspace to globalspace.
		Leadwerks::Vec3 pick_pos = Leadwerks::Transform::Point(pickinfo.position, pick, nullptr);
		//Create joint
		pick_joint = Leadwerks::Joint::Kinematic(pick_pos.x, pick_pos.y, pick_pos.z, pick);
		pick_joint->SetFriction(1000, 10000 - pick_mass * pick_mass * 10);

		joint_target_pos_gap = pick->GetPosition(true) - pick_pos;
	}
	else
	{
		Leadwerks::Vec3 camera_target_pos = camera_pivot->GetPosition(false);
		camera_target_pos.z += 1.2;

		camera_target_pos = Leadwerks::Transform::Point(camera_target_pos, camera_pivot, nullptr);
      
		//Joint work
		Leadwerks::Vec3 joint_target_pos = camera_target_pos + joint_target_pos_gap;
		pick_joint->SetTargetPosition(joint_target_pos, 1.0f - (pick_mass * 2.0)/100);
	}

	pick_state = PICK_UP;
	pick_image = hand_grab;
}

 

Additionally, the ClassName of the entities in the video are "Model", "PhysicsMode" is "RigidBodyPhysics" and "CollisionType" is "Prop".

And, the entitiy that did not 'pick' from 10 to 25 seconds of video were 'pick' after the collision at 27sec.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...