Digital-Humans-23 / a1

7 stars 0 forks source link

[Announcement] Hints for bonus exercise. #2

Open eastskykang opened 1 year ago

eastskykang commented 1 year ago

If you are already done with all exercises (and feel bored), please try bonus exercise for a more complex terrain loaded from a mesh file. If you manage to implement this successfully, you will get an extra 5% point (but your final point cannot exceed 100%)

This could be pretty complicated and may require a lot of code modifications. So please create a new branch called meshterrain and work there while keep your successful implementation of Ex.1~Ex.5 on the master (or main) branch. Again, please make sure your implementation of Ex.1 ~ Ex.5 stays safe in master (or main) branch. It's your responsibility to keep the main branch clean and working.

Successful implementation will looks like this:

image

Click this for demo video

You can download a terrain file you want to use from any internet source, but if it's hard to find one, you can use one in data directory data/terrain/terrain.obj

Note. You may need to read the code base thouroughly and spend quite some time.

Let me give some hints:

  1. You can create a 3D model from a mesh file by
// for instance... let's say we use terrain.obj file.
Model terrain = Model(CRL_DATA_FOLDER "/terrain/terrain.obj");
  1. You can draw a mesh by
// in app.h
virtual void drawObjectsWithShadows() override {
    // TODO: comment this line
    // ground.draw(shadowShader, V3D(0.6, 0.6, 0.8));

    // TODO: and add this
    terrain.draw(shadowShader);
    robot->draw(shadowShader);
}
  1. You can use the following function for getting a ground height
// member function of Model class
bool Model::hitByRay(const P3D &r_o, const V3D &r_v, P3D &hitPoint) const;

the strategy is as follows. From underground e.g. (x, -1.0, z), we will shoot a ray toward the sky (straight up) and then will find a hitPoint. The hitPoint.y is the ground height at (x, z) coordinate.