my solutions
Re: my solutions
https://youtu.be/7cBUaFc1H8Q?list=PLqCJ ... l43S&t=773
Will we get the same result if we don't normalize the vector from the intersection point to the circle?
We are taking the sign of the dotted product so does size take a role here?
Will we get the same result if we don't normalize the vector from the intersection point to the circle?
We are taking the sign of the dotted product so does size take a role here?
Re: my solutions
I should ask questions after watching the full video haha
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: my solutions
I'm guessing you got your answer?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: my solutions
Yeah, wait until you do Advanced 4. I show a way of getting the plank normal that is waaaay simpler.
Chili
Re: my solutions
Yes albinopapa, I got my answer at the end of the video.
After you explained how rotation works I went back to the starfield and tried to implement it.
Instead of calculating sin and cos for every object we are just going to change our direction unit vectors x hat and y hat.
So now we're applying rotation to the field, rather than every star.
added float dAngle to Camera.h so I have control over from Game::UpdateModel()
in camera.h
After you explained how rotation works I went back to the starfield and tried to implement it.
Instead of calculating sin and cos for every object we are just going to change our direction unit vectors x hat and y hat.
So now we're applying rotation to the field, rather than every star.
added float dAngle to Camera.h so I have control over from Game::UpdateModel()
Code: Select all
if (wnd.kbd.KeyIsPressed('D'))
{
cam.setAngle(cam.getAngle() + 0.01f);
}
if (wnd.kbd.KeyIsPressed('A'))
{
cam.setAngle(cam.getAngle() - 0.01f);
}
Code: Select all
void DrawClosedPolyline(Vec2 entityPos, std::vector<Vec2> poly,Color c)
{
Vec2 x = { cos(dAngle), sin(dAngle) };
Vec2 y = { -sin(dAngle), cos(dAngle) };
for( auto& v : poly )
{
v *= zoom;
v -= pos;
Vec2 rotatedX = x * v.x;
Vec2 rotatedY = y * v.y;
v = rotatedX + rotatedY;
}
ct.DrawClosedPolyline( std::move( poly ),c );
}
Re: my solutions
It might even be better to put this part
in Camera::setAngle and have x hat and y hat unit vectors as parameters.
Code: Select all
Vec2 x = { cos(dAngle), sin(dAngle) };
Vec2 y = { -sin(dAngle), cos(dAngle) };
Re: my solutions
https://youtu.be/cN97hkDrzcc?list=PLqCJ ... d8lA&t=172
Should we not get rotation in the LEFT direction when applying positive theta?
Take a look at the picture.
Should we not get rotation in the LEFT direction when applying positive theta?
Take a look at the picture.
- Attachments
-
- rotation.jpg
- (76.33 KiB) Not downloaded yet
Re: my solutions
Is it because, the y direction isn't flipped?
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: my solutions
Yes.randomGuy wrote:Is it because, the y direction isn't flipped?
Your yHat of { 0, 1 } would be pointing down, whereas your diagram would be more like { 0, -1 }
So, before rotation: { 95, -29 }, after
counter clockwise rotation in screen coordinates { -29, -95 } ( y,-x )
and clockwise rotation in screen coordinates : { 29, 95 }{ -y, x }
Flipping the Y before you do the rotation, you get something more mathematically correct.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: my solutions
https://youtu.be/9A5TVh6kPLA?list=PLqCJ ... 8lA&t=1824
The order in which triangles are drawn matters when we rotate so we need to draw the ones that are closest to us in the z direction last. We need to sort the indices array. I made a new class TriangleIndex which will hold an array of 3 indices and a color; Now our cube's array of indices holds TriangleIndex objects instead of just numbers so we can sort it before drawing.
So now how do we sort it? Our triangle has 3 points, which one do we pass to std::sort for comparing?
We pass the z value of the middle of the hypothenuse. But how do we get the hypothenuse of 3 points?
For each triangle index we make sure the first two points are the hypothenuse.
and the sorting goes like this
drawing
The order in which triangles are drawn matters when we rotate so we need to draw the ones that are closest to us in the z direction last. We need to sort the indices array. I made a new class TriangleIndex which will hold an array of 3 indices and a color; Now our cube's array of indices holds TriangleIndex objects instead of just numbers so we can sort it before drawing.
So now how do we sort it? Our triangle has 3 points, which one do we pass to std::sort for comparing?
We pass the z value of the middle of the hypothenuse. But how do we get the hypothenuse of 3 points?
For each triangle index we make sure the first two points are the hypothenuse.
Code: Select all
indices.emplace_back(2, 1, 0, w);//front
indices.emplace_back(2, 1, 3, w);
indices.emplace_back(3, 5, 1, b);//right
indices.emplace_back(3, 5, 7, b);
indices.emplace_back(6, 3, 2, c);//top
indices.emplace_back(6, 3, 7, c);
indices.emplace_back(4, 7, 5, g);//back
indices.emplace_back(4, 7, 6, g);
indices.emplace_back(2, 4, 0, gr);//left
indices.emplace_back(2, 4, 6, gr);
indices.emplace_back(1, 4, 0, m);//bottom
indices.emplace_back(1, 4, 5, m);
Code: Select all
std::sort(tIndices.begin(), tIndices.end(),
[&](const TriangleIndex & a, const TriangleIndex & b) -> bool
{
std::vector<size_t> indicesA = a.indices;
std::vector<size_t> indicesB = b.indices;
float hA = (triangles.vertices[indicesA[0]].z + triangles.vertices[indicesA[1]].z) / 2;
float hB = (triangles.vertices[indicesB[0]].z + triangles.vertices[indicesB[1]].z) / 2;
return hA > hB;
});
Code: Select all
for (TriangleIndex& tIndex : tIndices) {
Color c = tIndex.color;
std::vector<size_t> indices = tIndex.indices;
gfx.DrawTriangle(triangles.vertices[indices[0]], triangles.vertices[indices[1]],
triangles.vertices[indices[2]], c);
}