Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity's transformation matrix is the source of truth #23

Merged
merged 25 commits into from
Aug 25, 2017

Conversation

stasm
Copy link
Collaborator

@stasm stasm commented Aug 24, 2017

Still WIP, but already functional.

@stasm stasm changed the base branch from master to v1.0 August 24, 2017 16:46
@stasm
Copy link
Collaborator Author

stasm commented Aug 25, 2017

@michalbe I think this is finally ready for you review.

if (this.vertices && this.indices && this.normals) {
this.create_buffers();
}
}

look_at(vec, up = this.up) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this target_to?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so - look_at is self explanatory, I believe in this case we're having it better than gl-matrix. Keep in mind that Unity's look_at is doing exactly what ours is doing.

math.mat4.target_to(this.local_matrix, this.position, vec, up);
}

get left() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current coordinate system (Y = up) is left-handed, so it makes sense to rename right to left. Note that this isn't used anywhere else in the code right now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doooooo we need to keep this vector then? Since you've get rid of Entity::realign and all the computations are handled without it, I believe it became useless. Do you?

math.mat4.from_rotation(rotation_matrix, rad, vec);
math.mat4.translate(this.local_matrix, this.local_matrix, this.origin);
math.mat4.multiply(this.local_matrix, this.local_matrix, rotation_matrix);
math.mat4.translate(this.local_matrix, this.local_matrix, reverse_origin);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of the translations here is reversed compared to the current v1.0. I didn't get to test this yet, so this might be wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think that we should remove origin for now: the same effect can be achieved with parents. It's unclear to me right now if children's origin should be used for rotating them if the parent is rotated.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand your concerns here, maybe it's because origin isn't the most fortunate name for this attribute.
Lemme visualise my idea behind it.

Default origin

cube.origin = [0, 0, 0];
game.add_frame_listener('do_stuff', delta => {
  cube.rotate_rl(16/1000);
});

the cube's rotating in place.
rotate-no-origin

Non-default origin

cube.origin = [ -2, 0, 0];
game.add_frame_listener('do_stuff', delta => {
  cube.rotate_rl(16/1000);
});

The entity is still rotating, but the point of rotation (the origin) is displaced:
rotate-origin

Of course you can achieve the same thing with a parent entity, but it increases number of elements in scene, number of computations per frame, and is probably harder to use than just changing yet another attribute on the class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing more information about this. I filed #35.

-1, 0, 1,
1, 0, 1,
1, 0, -1,
-1, 0, -1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the new XYZ coordinates, the plane was rendered vertically rather than horizontally.

Copy link
Owner

@michalbe michalbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @stasm, I'm landing this right now. Let's discuss questions and concerns in separate issues.

Compiled Size: 5.79KB gzipped (18.85KB uncompressed)

if (this.vertices && this.indices && this.normals) {
this.create_buffers();
}
}

look_at(vec, up = this.up) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so - look_at is self explanatory, I believe in this case we're having it better than gl-matrix. Keep in mind that Unity's look_at is doing exactly what ours is doing.

math.mat4.target_to(this.local_matrix, this.position, vec, up);
}

get left() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doooooo we need to keep this vector then? Since you've get rid of Entity::realign and all the computations are handled without it, I believe it became useless. Do you?

math.mat4.from_rotation(rotation_matrix, rad, vec);
math.mat4.translate(this.local_matrix, this.local_matrix, this.origin);
math.mat4.multiply(this.local_matrix, this.local_matrix, rotation_matrix);
math.mat4.translate(this.local_matrix, this.local_matrix, reverse_origin);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand your concerns here, maybe it's because origin isn't the most fortunate name for this attribute.
Lemme visualise my idea behind it.

Default origin

cube.origin = [0, 0, 0];
game.add_frame_listener('do_stuff', delta => {
  cube.rotate_rl(16/1000);
});

the cube's rotating in place.
rotate-no-origin

Non-default origin

cube.origin = [ -2, 0, 0];
game.add_frame_listener('do_stuff', delta => {
  cube.rotate_rl(16/1000);
});

The entity is still rotating, but the point of rotation (the origin) is displaced:
rotate-origin

Of course you can achieve the same thing with a parent entity, but it increases number of elements in scene, number of computations per frame, and is probably harder to use than just changing yet another attribute on the class.

@michalbe michalbe merged commit e894a95 into michalbe:v1.0 Aug 25, 2017
@stasm stasm mentioned this pull request Aug 26, 2017
michalbe added a commit that referenced this pull request May 30, 2018
Entity's transformation matrix is the source of truth
michalbe added a commit that referenced this pull request May 30, 2018
Entity's transformation matrix is the source of truth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants