cutechicken commited on
Commit
2a18e50
ยท
verified ยท
1 Parent(s): 080df83

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +25 -12
game.js CHANGED
@@ -519,33 +519,46 @@ class Game {
519
  roughness: 0.8,
520
  metalness: 0.2
521
  });
522
-
523
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
524
  ground.rotation.x = -Math.PI / 2;
525
  ground.receiveShadow = true;
526
 
527
- // ๋” ์™„๋งŒํ•œ ์ง€ํ˜• ์ƒ์„ฑ
528
  const vertices = ground.geometry.attributes.position.array;
529
- const heightScale = 10; // ๋†’์ด ์Šค์ผ€์ผ ๊ฐ์†Œ
530
- const frequency = 0.005; // ์ฃผํŒŒ์ˆ˜ ๊ฐ์†Œ๋กœ ๋” ์™„๋งŒํ•œ ๊ฒฝ์‚ฌ ์ƒ์„ฑ
531
 
532
  for (let i = 0; i < vertices.length; i += 3) {
533
  const x = vertices[i];
534
  const y = vertices[i + 1];
535
- // Perlin ๋…ธ์ด์ฆˆ์™€ ์œ ์‚ฌํ•œ ํšจ๊ณผ๋ฅผ ๋‚ด๋Š” ์ˆ˜์ •๋œ ์ˆ˜์‹
536
- vertices[i + 2] =
537
- (Math.sin(x * frequency) * Math.cos(y * frequency) * heightScale) +
538
- (Math.sin(x * frequency * 2) * Math.cos(y * frequency * 2) * heightScale * 0.5);
539
 
540
- // ๋งต ๊ฐ€์žฅ์ž๋ฆฌ๋กœ ๊ฐˆ์ˆ˜๋ก ๋†’์ด๋ฅผ ์ ์ง„์ ์œผ๋กœ ์ค„์ž„
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
  const distanceFromCenter = Math.sqrt(x * x + y * y) / (MAP_SIZE * 0.5);
542
- const edgeFactor = Math.max(0, 1 - distanceFromCenter);
543
- vertices[i + 2] *= edgeFactor;
 
 
544
  }
545
 
546
  ground.geometry.attributes.position.needsUpdate = true;
547
  ground.geometry.computeVertexNormals();
548
- this.ground = ground; // ์ง€ํ˜• ์ฐธ์กฐ ์ €์žฅ
549
  this.scene.add(ground);
550
 
551
  // ์‚ฌ๋ง‰ ์žฅ์‹ ์ถ”๊ฐ€
 
519
  roughness: 0.8,
520
  metalness: 0.2
521
  });
 
522
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
523
  ground.rotation.x = -Math.PI / 2;
524
  ground.receiveShadow = true;
525
 
526
+ // ๋” ๋‹ค์–‘ํ•œ ์ง€ํ˜• ์ƒ์„ฑ
527
  const vertices = ground.geometry.attributes.position.array;
528
+ const heightScale = 15; // ๋†’์ด ์Šค์ผ€์ผ
529
+ const baseFrequency = 0.008; // ๊ธฐ๋ณธ ์ฃผํŒŒ์ˆ˜
530
 
531
  for (let i = 0; i < vertices.length; i += 3) {
532
  const x = vertices[i];
533
  const y = vertices[i + 1];
 
 
 
 
534
 
535
+ // ์—ฌ๋Ÿฌ ์ฃผํŒŒ์ˆ˜๋ฅผ ์กฐํ•ฉํ•œ ์ง€ํ˜• ์ƒ์„ฑ
536
+ let height = 0;
537
+
538
+ // ํฐ ์–ธ๋• (๊ธฐ๋ณธ ์ง€ํ˜•)
539
+ height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
540
+
541
+ // ์ค‘๊ฐ„ ํฌ๊ธฐ ์ง€ํ˜•
542
+ height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
543
+
544
+ // ์ž‘์€ ๊ตด๊ณก
545
+ height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
546
+
547
+ // ๋žœ๋ค ๋…ธ์ด์ฆˆ ์ถ”๊ฐ€ (์•„์ฃผ ์ž‘์€ ๊ตด๊ณก)
548
+ const noise = (Math.random() - 0.5) * heightScale * 0.1;
549
+ height += noise;
550
+
551
+ // ๋งต ๊ฐ€์žฅ์ž๋ฆฌ๋กœ ๊ฐˆ์ˆ˜๋ก ๋†’์ด๋ฅผ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ๊ฐ์†Œ
552
  const distanceFromCenter = Math.sqrt(x * x + y * y) / (MAP_SIZE * 0.5);
553
+ const edgeFactor = Math.pow(Math.max(0, 1 - distanceFromCenter), 2); // ๋ถ€๋“œ๋Ÿฌ์šด ๊ฐ์‡ 
554
+
555
+ // ์ตœ์ข… ๋†’์ด ์„ค์ •
556
+ vertices[i + 2] = height * edgeFactor;
557
  }
558
 
559
  ground.geometry.attributes.position.needsUpdate = true;
560
  ground.geometry.computeVertexNormals();
561
+ this.ground = ground;
562
  this.scene.add(ground);
563
 
564
  // ์‚ฌ๋ง‰ ์žฅ์‹ ์ถ”๊ฐ€