-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Skhuthon/feature/2
[#3] ๋ฐฉํ์ถ ํ ๋ง ์ถ์ฒ ํ๋ฉด
- Loading branch information
Showing
16 changed files
with
883 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from "react"; | ||
import { Theme } from "../styles/RoomThemeStyled"; | ||
|
||
const RoomTheme = () => { | ||
return ( | ||
<Theme> | ||
<div className="titleBox"> | ||
<p>๋ฐฉํ์ถ ํ ๋ง ์ด๋ฆ</p> | ||
</div> | ||
<div className="addressBox"> | ||
<p>๋งค์ฅ ์ ๋ณด</p> | ||
</div> | ||
<div className="cardFooter"> | ||
<div className="hashtagBox"> | ||
<p>#๋์ด๋</p> | ||
<p>#์ฅ๋ฅด</p> | ||
</div> | ||
<div className="linkBtn"> | ||
<p>์์ฝ ์ฌ์ดํธ</p> | ||
</div> | ||
</div> | ||
</Theme> | ||
); | ||
}; | ||
|
||
export default RoomTheme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ code { | |
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", | ||
monospace; | ||
} | ||
|
||
p { | ||
margin: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import * as THREE from "three"; | ||
|
||
const Cube = () => { | ||
const mountRef = useRef<HTMLDivElement>(null); | ||
const [mouseX, setMouseX] = useState(0); | ||
const [mouseY, setMouseY] = useState(0); | ||
const [isDragging, setIsDragging] = useState(false); | ||
const [previousMouseX, setPreviousMouseX] = useState(0); | ||
const [previousMouseY, setPreviousMouseY] = useState(0); | ||
const [initialRotation, setInitialRotation] = useState<THREE.Euler | null>( | ||
null | ||
); | ||
const [initialZoom, setInitialZoom] = useState(5); // ์ด๊ธฐ ์ค ๊ฐ์ ์ํ๋ก ๊ด๋ฆฌ | ||
|
||
useEffect(() => { | ||
const mount = mountRef.current; | ||
|
||
// Scene, Camera, Renderer ์์ฑ | ||
const scene = new THREE.Scene(); | ||
scene.background = null; // ๋ฐฐ๊ฒฝ์ ํฌ๋ช ํ๊ฒ ์ค์ | ||
|
||
const camera = new THREE.PerspectiveCamera( | ||
70, | ||
mount!.clientWidth / mount!.clientHeight, | ||
0.1, | ||
1000 | ||
); | ||
const renderer = new THREE.WebGLRenderer({ alpha: true }); // alpha ์์ฑ์ true๋ก ์ค์ | ||
renderer.setSize(mount!.clientWidth, mount!.clientHeight); | ||
mount!.appendChild(renderer.domElement); | ||
|
||
// ์กฐ๋ช | ||
const directionLight = new THREE.DirectionalLight(0xffffff, 1.5); | ||
directionLight.position.set(-0.7, 1, 5); | ||
scene.add(directionLight); | ||
|
||
// ํ๋ธ ์์ฑ (์์ ๋ณ๊ฒฝ) | ||
const geometry = new THREE.BoxGeometry(2, 2, 2); | ||
const material = new THREE.MeshPhysicalMaterial({ | ||
color: 0x03ff8d, | ||
metalness: 1, | ||
roughness: 0.5, | ||
transparent: true, | ||
opacity: 0.9, | ||
reflectivity: 0.9, | ||
}); | ||
const cube = new THREE.Mesh(geometry, material); | ||
scene.add(cube); | ||
|
||
camera.position.z = initialZoom; // ์ด๊ธฐ ์ค ๊ฐ ์ค์ | ||
|
||
// ๋ง์ฐ์ค ์ด๋ฒคํธ ๋ฆฌ์ค๋ | ||
const onMouseDown = (event: MouseEvent) => { | ||
setIsDragging(true); | ||
setPreviousMouseX(event.clientX); | ||
setPreviousMouseY(event.clientY); | ||
setInitialRotation(cube.rotation.clone()); // ํด๋ฆญ ์์ ์ ํ์ ์ํ ์ ์ฅ | ||
setInitialZoom(camera.position.z); // ํด๋ฆญ ์์ ์ ์ค ๊ฐ ์ ์ฅ | ||
}; | ||
|
||
const onMouseMove = (event: MouseEvent) => { | ||
if (isDragging) { | ||
const deltaX = event.clientX - previousMouseX; | ||
const deltaY = event.clientY - previousMouseY; | ||
|
||
if (initialRotation) { | ||
cube.rotation.y = initialRotation.y + deltaX * 0.005; | ||
cube.rotation.x = initialRotation.x + deltaY * 0.005; | ||
} | ||
|
||
setPreviousMouseX(event.clientX); | ||
setPreviousMouseY(event.clientY); | ||
} | ||
}; | ||
|
||
const onMouseUp = () => { | ||
setIsDragging(false); | ||
}; | ||
|
||
const onWheel = (event: WheelEvent) => { | ||
const delta = event.deltaY * 0.01; | ||
|
||
camera.position.z -= delta; | ||
|
||
// Limiting camera zoom | ||
if (camera.position.z < 4) { | ||
camera.position.z = 4; | ||
} else if (camera.position.z > 15) { | ||
camera.position.z = 15; | ||
} | ||
}; | ||
|
||
window.addEventListener("mousedown", onMouseDown); | ||
window.addEventListener("mousemove", onMouseMove); | ||
window.addEventListener("mouseup", onMouseUp); | ||
window.addEventListener("wheel", onWheel); | ||
|
||
if (previousMouseX > 0 || previousMouseY > 0) { | ||
cube.rotation.x -= previousMouseX; | ||
cube.rotation.y -= previousMouseY; | ||
} | ||
|
||
// ๋ฐ์ํ ์ฒ๋ฆฌ | ||
const onWindowResize = () => { | ||
if (mount) { | ||
camera.aspect = mount.clientWidth / mount.clientHeight; | ||
camera.updateProjectionMatrix(); | ||
renderer.setSize(mount.clientWidth, mount.clientHeight); | ||
} | ||
}; | ||
window.addEventListener("resize", onWindowResize); | ||
|
||
// ์ ๋๋ฉ์ด์ ๋ฃจํ | ||
const animate = () => { | ||
requestAnimationFrame(animate); | ||
|
||
// ๊ธฐ๋ณธ ํ์ | ||
if (!isDragging) { | ||
cube.rotation.x += 0.005; | ||
cube.rotation.y += 0.005; | ||
} | ||
|
||
renderer.render(scene, camera); | ||
}; | ||
animate(); | ||
|
||
// ํด๋ฆฐ์ ํจ์ | ||
return () => { | ||
mount!.removeChild(renderer.domElement); | ||
window.removeEventListener("mousedown", onMouseDown); | ||
window.removeEventListener("mousemove", onMouseMove); | ||
window.removeEventListener("mouseup", onMouseUp); | ||
window.removeEventListener("wheel", onWheel); | ||
window.removeEventListener("resize", onWindowResize); | ||
}; | ||
}, [isDragging, initialRotation, initialZoom]); | ||
|
||
return <div ref={mountRef} style={{ width: "100%", height: "100%" }} />; | ||
}; | ||
|
||
export default Cube; |
Oops, something went wrong.