首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
代做COMP27112、代写Java语言程序
项目预算:
开发周期:
发布时间:
要求地区:
Introduction to Visual Computing
Coursework Assignment 2
Sun, Planet and Moon
Tim Morris
Introduction
The aim of this exercise is to render a simple solar system with one moon orbiting one
planet orbiting one sun. As with the previous exercise, you’ll need a web browser to display
the output and a simple text editor1 to create the html file you’ll need.
This piece of work contributes half of the coursework assessment. We suggest that you
should not spend more than 15 hours in total completing Assignments 1 and 2.
Getting Started
Start off with the same code as last time for creating the basic webpage. Under “// Your
Javascript will go here.” you’ll add any global variables and calls to two
functions, init() and animate().
Creating the Scene (init();)
Everything is initialised in this function.
As before, add a scene, camera and renderer and add the renderer to the
document (don’t forget to declare the scene, camera and renderer as global
variables). You won’t need a vertex shader or fragment shader this time.
Put the far plane of the camera at 10000. Locate the camera at (0, 30, 500) and add it to the
scene.
You’ll need to create nine variables for the sun’s, earth’s and moon’s geometries, materials
and meshes. These are global variables.
You can create the sun object using the following code:
1 You should ensure that your text editor saves your html files as plain text. Some editors (e.g. TextEdit on the
Mac add all kinds of stuff to what you think is a plain html file, meaning that you just see the text of your file
when you open it in your browser. Don’t forget to give your files the correct extension.
You could also use a suitable IDE.
sunGeometry = new THREE.SphereGeometry(109, 400, 200);
sunMaterial = new THREE.MeshStandardMaterial(
{
emissive: 0xffd700,
// emissiveMap: texture,
emissiveIntensity: 1,
wireframe: false
}
);
sunMesh = new THREE.Mesh(sunGeometry, sunMaterial);
scene.add(sunMesh);
This creates a spherical object (what do the arguments mean?) of a particular colour. Where
is it located? The emissiveMap is something you may use later.
The sun must be a source of light. The PointLight() constructor can achieve this.
Create a point light source of white light at the origin and add it to the scene. You might also
add a diffuse light to give some background illumination, use AmbientLight().
Obviously this is physically unrealistic but it makes the objects more visible.
You can create the earth and moon using similar code with the following differences:
• The earth sphere geometry arguments are 25, 50, 50
• The moon sphere geometry arguments are 5, 40, 20
• Both the earth and moon materials are MeshPhongMaterial, they don’t have an
emissive argument, but do have a color. You can experiment with color
values.
The texture argument might be used later. So the earthMaterial can be created
using something like:
earthMaterial = new THREE.MeshPhongMaterial(
{
// map: texture,
color: x0000ff
}
The earth and moon will be grouped together into one object before being added to the
scene. To do this we need a global variable to store the earth-moon system, we need to
add the earth to it, by default it will go to the origin of this system. Then we need to add the
moon to the system and set its position relative to the earth.
Three.js provides a group object for storing collections:
earthSystem = new THREE.Group();
Then the earth (and moon) can be added to this in a manner that was similar to the way we
added the sun to the scene:
earthSystem.Add(earthMesh);
Don’t forget to set the position of the moon within the earth-moon system, using a function
something like:
moonMesh.position.set(orbitRadius, 0, 0);
A suitable value for orbitRadius is in the range 40 – 60.
The earth’s orbit could be approximated as a circle, and the location of the earth on it could
be computed as the following pseudocode:
earth.position.x = earthOrbitRadius * sin(2pwt);
earth.position.y = earthOrbitRadius * cos(2pwt);
w is the earth’s angular velocity and t is some measurement of time.
It is slightly more realistic to make the orbit an ellipse. To make this more efficient we precompute the co-ordinates of the earth’s orbit. Create a global variable with a suitable name.
The points can be computed by calling the function EllipseCurve. This has arguments
to define:
• The x co-ordinate of the centre point of the ellipse
• The y co-ordinate of the centre point of the ellipse
• The radius of the ellipse in the x direction
• The radius of the ellipse in the y direction
• The start angle for drawing the ellipse (in this case 0 radians)
• The end angle for drawing the ellipse (in this case 2p radians)
• Plus other arguments that can take default values.
You may choose to draw the orbit, in which case you will have to
• Transfer points from the orbit into a line buffer
• Create a geometry (using BufferGeometry) from these points
• Create a material (using LineBasicMaterial) and setting a suitable colour
• Create a line object using the geometry and material
• Rotate the line so it lies in the XZ plane instead of the default XY plane
• Add it to the scene
Animation (Animate();)
The basic animation function will contain the two lines to render the scene and request an
animation frame, as in the previous exercise. If you’ve followed the instructions so far and
now implement this, you’ll see a static scene with the sun, earth and moon in fixed positions
and the earth orbit (if you chose to draw it). The earth and moon should be solid coloured
spheres. The next step is to add movement to the objects. The following code should be
added to Animate() before the two lines you’ve just written.
The sun’s movement is simple. It doesn’t move. You might want to make it rotate if you add
a texture to it, which will be done later.
The earth-moon system’s position could be driven by using a counter that is incremented
for each frame of the animation. But we’ll use the time instead. A time can be obtained by
calling performance.now(). This gives the time in milliseconds since the browser
window was opened. This can be converted into a value in the range [0, 1) which will be
used as an index into the values of the EllipseCurve you defined earlier. In
pseudocode:
time = 0.00001 * performance.now();
t = (time mod 1)
We can get the earth-moon position by reading a point from the EllipseCurve object
(assume it’s called curve):
point = curve.getPoint(t)
Then the earthSystem’s x and z positions can be set to point.x and point.y
respectively. Changing the value of the multiplier (0.00001) will change the earth’s orbital
speed.
The moon’s position is set according to
moon.x = orbitRadius*cos(time*speed)
moon.z = orbitRadius*sin(time*speed)
Time was derived above. Speed is the orbital speed of the moon – you choose a sensible
value.
Optional Enhancements
Some optional enhancements follow.
Changing the viewpoint
It is possible to change the observer’s viewpoint by adding the following controls.
Insert the following line after the other import statement.
import { OrbitControls } from
"https://web.cs.manchester.ac.uk/three/three.jsmaster/examples/jsm/controls/OrbitControls.js";
Add a global variable with a suitable name, possibly controls.
Add the following two lines to the init() function:
controls = new OrbitControls(camera, renderer.domElement);
controls.autoRotate = true;
These add a controller to the scene and allow you to move the viewpoint by clicking and
dragging.
Texturing
The sun, earth and moon can be textured using textures from
https://www.solarsystemscope.com/textures/download/2k_sun.jpg
https://upload.wikimedia.org/wikipedia/commons/a/ac/Earthmap1000x500.jpg
https://svs.gsfc.nasa.gov/vis/a000000/a004700/a004720/lroc_color_poles_1k.jpg
To read these you’ll have to create one texture loader
const loader = new THREE.TextureLoader();
Textures can be loaded using this
var texture = loader.load(‘filename’); OR
var texture = loader.load(‘URL’);
And added to the material of the object you’re creating, by uncommenting the line in the
example above where you created the sun object.
The earth and moon textures can be added similarly, except you’ll add the line
map: texture,
to the material constructor. You’ll also need to delete the color property.
The problem you may encounter when attempting to run the code is that the resource fails
to load, and you have an error message such as
Access to image at
from origin 'null' has been blocked by CORS policy
This is a security feature of most modern browsers. You can set up a server on your host to
overcome this problem. Instructions are widely available on the web, specifically here
https://threejs.org/docs/index.html#manual/en/introduction/How-to-run-things-locally
If you’re using Chrome you can alternatively install an extension that allows CORS cross
origin loading (https://chrome.google.com/webstore/detail/allow-cors-accesscontrol/lhobafahddgcelffkeicbaginigeejlf?hl=en). Or in Safari you can explicitly turn off the
CORS checking.
Rotations
You can make the sun, Earth and Moon rotate on their axes, much like the cube rotated in
the previous exercise. Make sure you choose an appropriate length of the “day”.
Clouds
You could add clouds to the Earth. Find a cloud image (e.g.
https://i.stack.imgur.com/B3c7G.jpg) and add it as a transparent texture to a sphere mesh
that is slightly larger than the Earth. Make it rotate slightly slower than the Earth.
Background
You can also create a starry background for the scene. Make a very large sphere mesh – to
make sure it’s big enough to contain everything. Add a texture image of the Milky Way:
https://cdn.eso.org/images/screen/eso0932a.jpg
Make the sphere visible from inside as well as outside by setting the side member of the
material to THREE.DoubleSide.
Submission
Once you have a working solution, capture a short video of your solution, no more than 15
seconds long. It must demonstrate all the properties of your solar system, and not so
quickly that the marker can’t see them clearly (you’ll be penalised for videos that have so
much zooming or camera movement that it’s impossible to see the earth or moon rotating).
ZIP this and your html and submit the file to the Lab 2 area in Blackboard.
Submissions that are not in the ZIP format will not be marked.
Marking Scheme
We will endeavour to mark your work in face-to-face sessions in the scheduled labs.
You will receive marks for:
• The objects being in appropriate locations and moving appropriately.
• Sensible illumination.
• Enhancements
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
mgt202代写、代做java/python编...
2025-06-28
代做pbt205—project-based le...
2025-06-28
代写comp3702 artificial inte...
2025-06-28
代写cs3214 fall 2022 project...
2025-06-28
代写turnitin assignment代做迭...
2025-06-28
代写finite element modelling...
2025-06-28
代做stat3600 linear statisti...
2025-06-28
代写problem set #3帮做matlab...
2025-06-28
代做elen90066 embedded syste...
2025-06-28
代做automatic counting of du...
2025-06-28
代做ct60a9602 functional pro...
2025-06-28
代写stat3600 linear statisti...
2025-06-28
代写csci 1110: assignment 2帮...
2025-06-28
热点标签
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
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!