ncollide icon indicating copy to clipboard operation
ncollide copied to clipboard

Type mismatch in example

Open janhohenheim opened this issue 8 years ago • 5 comments

Im trying to learn how to use the crate by following the collision pipeline example.

However, the following line, as it appears in the example, seems to no longer compile:

// Integrate the positions.
ball_pos = ball_object.position.append_translation(&(timestep * ball_velocity.get()));

Fails with

note: expected type `&nalgebra::TranslationBase<f32, nalgebra::U2, nalgebra::MatrixArray<f32, nalgebra::U2, nalgebra::U1>>`
         found type `&nalgebra::Matrix<f32, nalgebra::U2, nalgebra::U1, nalgebra::MatrixArray<f32, nalgebra::U2, nalgebra::U1>>`

Does anyone know how to fix this?

janhohenheim avatar Jul 25 '17 12:07 janhohenheim

The documentation seems to be out-of-date. This should be:

ball_pos = ball_object.position.append_translation(&Translation::from_vector(timestep * ball_velocity.get()));

sebcrozet avatar Jul 26 '17 00:07 sebcrozet

Thank you very much :)
It compiled after using your code with an extra unwrap, as from_vector returns an Option.
Now I've got a runtime error five lines above it:

// Integrate the velocities.
let ball_object   = world.collision_object(8).unwrap();

panics as it's unwrapping None.

Any idea what that might be?

janhohenheim avatar Jul 26 '17 07:07 janhohenheim

Did you keep the following line fom the example ?

// Add the ball to the world.
world.deferred_add(8, ball_pos, ball, ball_groups, GeometricQueryType::Contacts(0.0), ball_data);

ncollide identifies objects with user-supplied integers. world.collision_object(8) returning None means that no object whith the ID 8 has been added before.

sebcrozet avatar Jul 26 '17 14:07 sebcrozet

Yup, got it exactly as is. The other identifiers return None as well.

This is my entire code, but apart from the Translation::from_vector and the extern crate uses it's just copy pasted from the example.

janhohenheim avatar Jul 26 '17 15:07 janhohenheim

I found the problem!
It works if right after

// Add the ball to the world.
world.deferred_add(8, ball_pos, ball, ball_groups, GeometricQueryType::Contacts(0.0), ball_data);

we use

world.update()

Although I have to ask if this behavior is intentional or a bug.

janhohenheim avatar Jul 27 '17 09:07 janhohenheim