Jump to content

what's wrong with this code?


photo

Recommended Posts

I have two players in scene, actor and spectator, I need to switch from one to another, if current player is spectator, using specator's transfrom to set the actor's transfrom, this action is fine, no any problem, but if I want to switch from actor to spectator, the spectator alwasy moves a little, I use these code to calculate the transfrom matrix:

	vec3 pos = actor.getWorldPosition();
	mat4 trans = rotateZ(-actor.getPhiAngle()) * rotateY(actor.getThetaAngle());
	vec3 direction = normalize(trans.m00m10m20);
	pos.z += actor.getCollisionHeight() + actor.getCollisionRadius();

	trans = Unigine::composeTransformDirection(pos, direction);

 

this code should work as expected, but why everytime I switch from actor to spectator, the spectator always moves a little, many times it moves downward a little, some time it will move backward a little, any way the move distance is random.

 

Why this happens? I've tried to set both player not controlled, then set the matrix, but there is no difference.

Link to comment

As a reference sample, please, see the following demos:

1. \data\demos\sanctuary\sanctuary.cpp

2. \data\demos\heaven\camera.h

Try to set initial parameters for both players:

	// spectator player
	spectator = new PlayerSpectator();
	spectator.setCollisionRadius(1.05f);
	spectator.setMinVelocity(10.0f);
	spectator.setMaxVelocity(30.0f);
	spectator.setZNear(znear);
	spectator.setZFar(zfar);

	// actor player
	actor = new PlayerActor();
	actor.setCollisionRadius(1.05f);
	actor.setMaxVelocity(6.0f);
	actor.setMinVelocity(3.0f);
	actor.setDamping(0.0f);
	actor.setPhysicalMass(3.0f);
	actor.setCollisionHeight(1.0f);
	actor.setJumping(1.0f);

Link to comment

yes, I've saw the source, the both use a dummy player, but I don't think the dummy player is a necessary node for this kind of operation.

 

I've also set all these parameters. and I've found a intresting problem. the heaven demo also have this problem. try this, set current camera to walk-through, then switch to free camera,

 

the free camera isn't placed exactly as the walk camera. there is a little movement.

 

the intresting thing is, after I calculated and set the matrix for spectator, then test the position of this matrix in same frame update, it's excatly same value, but if I loaded the editor, the z value of position of spectator is below the calculated position. see the attachement.

 

post-49-058211500 1287047097_thumb.jpg

the calculated position of matrix

 

post-49-008199300 1287047107_thumb.jpg

the final position showed in editor's tool setting window.

 

everytime, the calculated z equals z-2.0 of the tools windows position.

Link to comment
×
×
  • Create New...