代写Assignment 3: Creating a Virtual World代做留学生Java程序

Assignment 3: Creating a Virtual World (Hard)

Objectives:

To create a virtual world using textured cubes and explore it using a perspective camera.

Introduction:

You will create a first-person exploration application. Your application should look like the following example:

A first-person camera (the player) should start in a given position of a 32x32x4 voxel-based 3D world (which is made out of textured cubes). The user should be able to navigate in this world using the keyboard and/or mouse to move and rotate the camera. Your application is required to have the following features:

The world is fully created when the application starts.

Ground is created with a large plane (square), or the top of a flattened (scaled) cube.

Walls are created with cubes.

Walls can have different heights in units (1 cube, 2 cubes, 3 cubes and 4 cubes).

The faces of the cube should be textured to make it look like a wall.

The sky is created with a very large blue cube that is placed at the center of the world

The world layout should be specified using a hardcoded javascript. 2D array.

Each element of the array represents the height of the wall (0, 1, 2, 3 or 4) that will be placed at that location.

Camera can be moved using the keyboard.

W moves camera forward.

A moves camera to the left.

S moves camera backwards

D moves camera to the right.

Q turn camera left

E turn camera right

Additional requirements without helper videos:

Camera can be rotated with the mouse.

Add multiple textures to make your world more interesting.

Simple Minecraft: add and delete blocks in front of you.

Add your animal(s) to your world

Change your ground plane from a flat plane to a terrain map OR get OBJ loader working

Add some sort of simple story or game to your world

Instructions:

The following will walk you through each point of the basic rubric. Note that the written suggestions and video suggestions are not exactly the same. One may suggest to build a Class, while one just sticks a global variable. Or one may stick an 'if' statement in the shader while the other suggests an interpolation. Either is fine, or your own method is fine. You should do what you think makes cleaner better code.

0. Start a local web server.

Before we can load a texture file, we are going to need a web server. You can't just click the html file anymore because of security issues. The book gives a way to bypass security and just use the browser, but you shouldn't bypass security. Make sure you can view your webpage through this local server.

There is no rubric point for this since its not observable in your final output.

- Texture Mapping (Matsuda Chapter 5)

This section will guide you to solve the following rubric points:

Texture working on at least one object.

Texture on some objects and color on some other objects. All working together.

1. Create a new attribute variable to store texture (UV) coordinates.

Read Matsuda pages 137-145.

Decide whether you want to use an extra buffer (textbook pages 137-140) or interleave a single buffer (textbook pages 141-145).

Either works, but make sure you can get this new attribute variable working.

You should be able to give each vertex a different UV coordinate.

There is no rubric point for this since its not observable in your final output, but you need it working to get the texture working.

2. Load Texture from the filesystem.

Read Matsuda pages 146-178.

Use the TexturedQuad example (functions initTextures and loadTexture) to load a texture file (e.g. sky.jpg) from your filesystem.

Your texture must be square and size is a power of 2. e.g. 64x64 or 1024x1024. Resize it with an external program if you need to.

3. Pass the Texture to the fragment shader.

Read Matsuda pages 179-181.

Use the TexturedQuad example (fragment shader) to look up colors from texture.

4. Mix base color with texture color.

Your sky will be a gigantic cube with solid blue color surrounding the world. Your walls would be made of unit boxes that are textured. Thus, you need to use solid base colors in one object and textures in others.

Create a new uniform. variable (e.g. called u_texColorWeight) to linear interpolate between a given base color and the texture color.

For example, assuming the base color is stored in a uniform. baseColor and the texture color in another variable texColor. You can linear between this two colors as follows:

t = u_texColorWeight

gl_FragColor = (1 - t) * baseColor + t * texColor

Note that you can use u_texColorWeight=0 if you want only base color (for the sky box) and u_baseColorWeight=1 if you want only texture colors (for the walls).

- Camera (Matsuda Chapter 7)

This section will guide you to solve the following rubric points:

Implement camera movement.

Key commands for rotation work. Use Q (rotate left) & E (rotate right).

Perspective camera implemented.

5. Include both View and Projection matrices in your vertex shader.

Read Matsuda pages 179-181.

Use example "PerspectiveView_mvp" (vertex shader) to update your vertex shader to:

glPosition = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * a_position;

Note that the book has lots of examples that have some matrices, but not others. I believe this project is conceptually easier if you pass all three as uniforms to the vertex shader and multiply them there.

6. Create a Camera class to store and control both View and Projection matrices.

Create a new file called camera.js and define a class called Camera that has the following attributes:

fov (field of view - float), initialize it to 60.

eye (Vector3), initialize it to (0,0,0).

at (Vector3), initialize it to (0,0,-1).

up (Vector3), initialize it to (0,1, 0).

viewMatrix (Matrix4), initialize it with viewMatrix.setLookAt(eye.elements[0], ... at.elements[0], ..., up.elements[0], ...).

projectionMatrix (Matrix4), initialize it with projectionMatrix.setPerspective(fov, canvas.width/canvas.height, 0.1, 1000).

In your camera class, create a function called "moveForward":

Compute forward vector f = at - eye.

Create a new vector f: let f = new Vector3();

Set f to be equal to at: f.set(at);

Subtract eye from f: f.sub(eye);

Normalize f using f.normalize();

Scale f by a desired "speed" value: f.mul(speed)

Add forward vector to both eye and center: eye += f; at += f;

In your camera class, create a function called "moveBackwards":

Same idea as moveForward, but compute backward vector b = eye - at instead of forward.

In your camera class, create a function called "moveLeft":

Compute forward vector f = at - eye.

Compute side vector s = up x f (cross product between up and forward vectors).

Normalize s using s.normalize();

Scale s by a desired "speed" value: s.mul(speed)

Add side vector to both eye and center: eye += s; at += s;

In your camera class, create a function called "moveRight":

Same idea as moveLeft, but compute the opposite side vector s = f x up.

In your camera class, create a function called "panLeft":

Compute the forward vector f = at - eye;

Rotate the vector f by alpha (decide a value) degrees around the up vector.

Create a rotation matrix: rotationMatrix.setRotate(alpha, up.x, up.y, up.z).

Multiply this matrix by f to compute f_prime = rotationMatrix.multiplyVector3(f);

Update the "at"vector to be at = eye + f_prime;

In your camera class, create a function called "panRight":

Same idea as panLeft, but rotate u by -alpha degrees around the up vector.

7. Set View matrix using keyboard input.

In your main function, instantiate a global camera object.

camera = new Camera()

When user hits W, call camera.moveForward()

When user hits S, call camera.moveBackwards()

When user hits A, call camera.moveLeft()

When user hits Q call camera.panLeft()

When user hits E call camera.panRight()

- World Creation

Make sure you have your camera working already with keyboard control. If not, go do that section first. You can't debug your world if you cant actually see all of it.

This section will guide you to solve the following rubric points:

Have a ground created with a flattened cube and sky from a big cube.

World is implemented. There is some interesting world (or terrain) to walk around.

8. Add a ground to the world.

Create a cube using the code you wrote in Assignment 2.

Scale the cube on the y axis to make it a flat plane.

Rotate this cube to put it in the x-z plane.

9. Add a sky box to the world.

Create a cube using the code you wrote in Assignment 2.

Place this cube in the center of the world and scale it by a very high number (e.g. 1000).

10. Add walls to the world.

Placing cubes manually in the world will genuinely suck if you need 100s of cubes to specify your world. Instead we will build it programatically.

Define a small 2D array: map = [[ 1 0 0 1] [1 1 0 1] [ 1 0 0 1] [ 1 1 1 1 ]].

Write a double loop to create a wall wherever there is a 1.

walls = []; for x = 1 ... 4: for z = 1 .. 4: if map[i][j] == 1 { let w = new Cube(); w.translate(x, 0, z); walls.push(w); } } }.

Expand your map to 32x32.

Instead of just making a 1 unit wall, make the wall N units high according to what you put in the 2d map array.

Include a third for loop to iterate on the height and translate the y coordinates of the walls.

You don't need to specify your map exactly like this if you want to be more fancy. Making just walls wont allow your world to have ceilings. You just need to end up with a world that is at least 32x32. You can't just write 100 hardcoded calls to drawCube() in your code. You should be able to 'edit the map'.

- Requirements without helper videos

Rotate camera with mouse.

- Most games have this control. You need to add an onMove() function and map this to the rotation you previously had on QE keys. Its a little tricky since with keys you can just turn 5degrees, but with mouse you have to keep track of the old mouse location and figure out an appropriate amount to turn based on the new mouse location.

Multiple textures

The book talks about multiple textures on pg 183. The easiest way to handle multiple textures is to just set up the samplers and texture units for all the textures and then just leave them (you dont need to pass all the textures with each drawArrays(), they will stay there). Just use a uniform. variable to specify which texture to use and update this uniform. before each call to drawCube(). Now different cubes can have different textures. You'll have to modify your map to say which kind of cube to draw as well. You may want to update your sky to have a different texture and ground as well. You can have up to 8 textures at a time loaded in webGL.

Simple Minecraft

Add and delete blocks in front of you. You do not need a raytracer, and you dont need full 3D pointing. You know your camera location and you know your map. Just find the map square right in front of you and add or delete a block from the stack of blocks that is there. Its super cool if you can save/load whatever world your create, but not required.

Add some sort of simple story or game to your world

e.g. Your animal takes care of a herd of baby animals, or pacman, or mini-minecraft and the mob wants to get you, or your animal puts on a puppet show as a story plays,. Use your creativity!

Performance

You may have efficiency issues, most people do on this assignment. If this is the case reduce world size until you can debug and interact. However to get this rubric point, you need to run 10fps with a full 32x32 world.

Wow!

This is intentionally vague. Its meant to leave you some space to do something you want to spend time on. You could make an impressive beautiful world. Past versions of this assignment talked about adding OBJ files or terrain maps to make it unique. But whatever you do, your goal is Wow!

FAQ:

But I want to load my world from a file. Hard coding is stupid! - Yep. Hard coding is stupid. But its much easier. Load from a file if you want to do that. Then you can even load different 'game levels' from different files.

How can I improve performance? - The primary issue is likely that you are rendering only one triangle at a time (since thats how the videos have showed it). That is, calling drawArrays() for each triangle. This is inefficient. It is possible to stack all the triangles you want to draw into a single vertexList and pass the whole thing to a single drawArrays() call. This will be much more efficient. The other big efficiency issue is allocating memory that is then garbage collected. Minimize the number of times new() is called in your code. If its in your rendering loop and happening every frame, then its probably too much.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图