mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-20 20:35:43 +01:00
feat: tighter cam fit
This commit is contained in:
1 parent
1281503de9
commit
5a34a35638
5 files changed
+44
-24
No files matched your search
+10
-10
@@ -3,6 +3,7 @@ import { invalidate, useThree } from '@react-three/fiber';
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { PerspectiveCamera, Vector3 } from 'three';
|
import { PerspectiveCamera, Vector3 } from 'three';
|
||||||
import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
|
import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
|
||||||
|
import { degToRad } from 'three/src/math/MathUtils.js';
|
||||||
import { awaitableModelDefinitions } from '../../../../../../core/awaitables/modelDefinitions';
|
import { awaitableModelDefinitions } from '../../../../../../core/awaitables/modelDefinitions';
|
||||||
import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits';
|
import { applyPitchYawLimits } from '../../../../../../core/blitz/applyPitchYawLimits';
|
||||||
import { hasEquipment } from '../../../../../../core/blitzkit/hasEquipment';
|
import { hasEquipment } from '../../../../../../core/blitzkit/hasEquipment';
|
||||||
@@ -19,7 +20,7 @@ const poseDistances: Record<Pose, number> = {
|
|||||||
|
|
||||||
const modelDefinitions = await awaitableModelDefinitions;
|
const modelDefinitions = await awaitableModelDefinitions;
|
||||||
|
|
||||||
const ARCADE_MODE_DISTANCE = 19;
|
const ARCADE_MODE_DISTANCE = 16;
|
||||||
const ARCADE_MODE_ANGLE = Math.PI / 8;
|
const ARCADE_MODE_ANGLE = Math.PI / 8;
|
||||||
|
|
||||||
export const ARCADE_MODE_FOV = 54;
|
export const ARCADE_MODE_FOV = 54;
|
||||||
@@ -73,13 +74,11 @@ export function Controls() {
|
|||||||
const [autoRotate, setAutoRotate] = useState(
|
const [autoRotate, setAutoRotate] = useState(
|
||||||
display !== TankopediaDisplay.ShootingRange,
|
display !== TankopediaDisplay.ShootingRange,
|
||||||
);
|
);
|
||||||
let initialPosition = [
|
const gunHeight =
|
||||||
-8,
|
|
||||||
protagonistHullOrigin.y +
|
protagonistHullOrigin.y +
|
||||||
protagonistTurretOrigin.y +
|
protagonistTurretOrigin.y +
|
||||||
protagonistGunOrigin.y,
|
protagonistGunOrigin.y;
|
||||||
-13,
|
const initialPosition = [-8, gunHeight + 4, -13] as const;
|
||||||
] as const;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!orbitControls.current) return;
|
if (!orbitControls.current) return;
|
||||||
@@ -88,16 +87,16 @@ export function Controls() {
|
|||||||
(camera as PerspectiveCamera).fov = ARCADE_MODE_FOV;
|
(camera as PerspectiveCamera).fov = ARCADE_MODE_FOV;
|
||||||
camera.position.set(
|
camera.position.set(
|
||||||
0,
|
0,
|
||||||
initialPosition[1] + ARCADE_MODE_DISTANCE * Math.sin(ARCADE_MODE_ANGLE),
|
gunHeight + ARCADE_MODE_DISTANCE * Math.sin(ARCADE_MODE_ANGLE),
|
||||||
ARCADE_MODE_DISTANCE * Math.cos(ARCADE_MODE_ANGLE),
|
ARCADE_MODE_DISTANCE * Math.cos(ARCADE_MODE_ANGLE),
|
||||||
);
|
);
|
||||||
orbitControls.current.target.set(0, initialPosition[1] + 3, 0);
|
orbitControls.current.target.set(0, gunHeight + 3, 0);
|
||||||
orbitControls.current.enablePan = false;
|
orbitControls.current.enablePan = false;
|
||||||
orbitControls.current.enableZoom = false;
|
orbitControls.current.enableZoom = false;
|
||||||
} else {
|
} else {
|
||||||
(camera as PerspectiveCamera).fov = INSPECT_MODE_FOV;
|
(camera as PerspectiveCamera).fov = INSPECT_MODE_FOV;
|
||||||
camera.position.set(...initialPosition);
|
camera.position.set(...initialPosition);
|
||||||
orbitControls.current.target.set(0, initialPosition[1] / 2, 0);
|
orbitControls.current.target.set(0, gunHeight / 2, 0);
|
||||||
orbitControls.current.enablePan = true;
|
orbitControls.current.enablePan = true;
|
||||||
orbitControls.current.enableZoom = true;
|
orbitControls.current.enableZoom = true;
|
||||||
}
|
}
|
||||||
@@ -243,6 +242,7 @@ export function Controls() {
|
|||||||
enabled={tankopediaEphemeralStore.getState().controlsEnabled}
|
enabled={tankopediaEphemeralStore.getState().controlsEnabled}
|
||||||
rotateSpeed={0.25}
|
rotateSpeed={0.25}
|
||||||
enableDamping={false}
|
enableDamping={false}
|
||||||
|
maxPolarAngle={degToRad(100)}
|
||||||
autoRotate={autoRotate}
|
autoRotate={autoRotate}
|
||||||
autoRotateSpeed={1 / 4}
|
autoRotateSpeed={1 / 4}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+26
-5
@@ -1,10 +1,13 @@
|
|||||||
import { Environment } from '@react-three/drei';
|
import { Environment } from '@react-three/drei';
|
||||||
|
import { times } from 'lodash-es';
|
||||||
import { useModel } from '../../../../../../hooks/useModel';
|
import { useModel } from '../../../../../../hooks/useModel';
|
||||||
import { Duel } from '../../../../../../stores/duel';
|
import { Duel } from '../../../../../../stores/duel';
|
||||||
import { TankopediaEphemeral } from '../../../../../../stores/tankopediaEphemeral';
|
import { TankopediaEphemeral } from '../../../../../../stores/tankopediaEphemeral';
|
||||||
import { TankopediaPersistent } from '../../../../../../stores/tankopediaPersistent';
|
import { TankopediaPersistent } from '../../../../../../stores/tankopediaPersistent';
|
||||||
import { TankopediaDisplay } from '../../../../../../stores/tankopediaPersistent/constants';
|
import { TankopediaDisplay } from '../../../../../../stores/tankopediaPersistent/constants';
|
||||||
|
|
||||||
|
const LIGHTS_COUNT = 5;
|
||||||
|
|
||||||
export function Lighting() {
|
export function Lighting() {
|
||||||
const protagonist = Duel.use((state) => state.protagonist);
|
const protagonist = Duel.use((state) => state.protagonist);
|
||||||
const display = TankopediaEphemeral.use((state) => state.display);
|
const display = TankopediaEphemeral.use((state) => state.display);
|
||||||
@@ -18,11 +21,29 @@ export function Lighting() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Environment
|
{display !== TankopediaDisplay.ShootingRange && (
|
||||||
preset={environment}
|
<Environment
|
||||||
background={showEnvironment}
|
preset={environment}
|
||||||
environmentIntensity={isBrighterLighting ? 3 : 1}
|
background={showEnvironment}
|
||||||
/>
|
environmentIntensity={isBrighterLighting ? 3 : 1}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{display === TankopediaDisplay.ShootingRange && (
|
||||||
|
<>
|
||||||
|
<directionalLight position={[0, -1, 0]} />
|
||||||
|
|
||||||
|
{times(LIGHTS_COUNT, (index) => (
|
||||||
|
<directionalLight
|
||||||
|
castShadow
|
||||||
|
position={[
|
||||||
|
Math.sin(2 * Math.PI * (index / LIGHTS_COUNT)),
|
||||||
|
1,
|
||||||
|
Math.cos(2 * Math.PI * (index / LIGHTS_COUNT)),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+5
-5
@@ -31,11 +31,11 @@ export function SceneProps() {
|
|||||||
)}
|
)}
|
||||||
{display === TankopediaDisplay.ShootingRange && (
|
{display === TankopediaDisplay.ShootingRange && (
|
||||||
<>
|
<>
|
||||||
{/* <TransformControls>
|
{/* <fog color="black" /> */}
|
||||||
<mesh rotation={[-Math.PI / 2, 0, 0]}>
|
<mesh rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
|
||||||
<boxGeometry args={[1, 1, 1]} />
|
<planeGeometry args={[100, 100]} />
|
||||||
</mesh>
|
<meshStandardMaterial color={0x404040} />
|
||||||
</TransformControls> */}
|
</mesh>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
+3
-3
@@ -102,7 +102,7 @@ export const TankModel = memo(() => {
|
|||||||
return jsxTree(
|
return jsxTree(
|
||||||
node,
|
node,
|
||||||
{
|
{
|
||||||
mesh: { onPointerDown },
|
mesh: { onPointerDown, castShadow: true },
|
||||||
// group(group) {
|
// group(group) {
|
||||||
// return {
|
// return {
|
||||||
// visible:
|
// visible:
|
||||||
@@ -194,7 +194,7 @@ export const TankModel = memo(() => {
|
|||||||
return jsxTree(
|
return jsxTree(
|
||||||
node,
|
node,
|
||||||
{
|
{
|
||||||
mesh: { onPointerDown },
|
mesh: { onPointerDown, castShadow: true },
|
||||||
// group(group) {
|
// group(group) {
|
||||||
// return {
|
// return {
|
||||||
// visible:
|
// visible:
|
||||||
@@ -289,7 +289,7 @@ export const TankModel = memo(() => {
|
|||||||
return jsxTree(
|
return jsxTree(
|
||||||
node,
|
node,
|
||||||
{
|
{
|
||||||
mesh: { onPointerDown },
|
mesh: { onPointerDown, castShadow: true },
|
||||||
// group(group) {
|
// group(group) {
|
||||||
// return {
|
// return {
|
||||||
// visible:
|
// visible:
|
||||||
|
|||||||
-1
@@ -177,7 +177,6 @@ export const TankSandbox = forwardRef<HTMLCanvasElement, TankSandboxProps>(
|
|||||||
style={{ userSelect: 'none' }}
|
style={{ userSelect: 'none' }}
|
||||||
camera={{
|
camera={{
|
||||||
fov: INSPECT_MODE_FOV,
|
fov: INSPECT_MODE_FOV,
|
||||||
far: 32,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Controls />
|
<Controls />
|
||||||
|
|||||||
Reference in new issue
Block a user