Skip to content

Commit

Permalink
BINARY PLANET SYSTEM + COLLISION LOGIC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
RidwanSharkar committed Nov 19, 2024
1 parent 6acf08c commit 06441fb
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 41 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Planetfolio v2.2
# Planetfolio v3.0
- Collision Logic
- Hyperbolic Trajectory
- Sun Gravity Influence
- Binary Planet System

![Planetfolio v2 0](https://github.com/user-attachments/assets/67420c06-3db2-4496-9796-9b7cdd9e9ee7)

# Planetfolio v2.0
- HUD Interface
- Exoplanets

![Planetfolio v2 0](https://github.com/user-attachments/assets/67420c06-3db2-4496-9796-9b7cdd9e9ee7)
2 changes: 1 addition & 1 deletion warpgate/CelestialObjectGlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface GlowProps {
export const CelestialObjectGlow: React.FC<GlowProps> = ({
color,
size,
intensity = 0.3,
intensity = 0.4,
isSelected = false,
}) => {
const glowRef = useRef<ShaderMaterial>(null);
Expand Down
40 changes: 33 additions & 7 deletions warpgate/EnhancedPlanet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ interface EnhancedPlanetProps extends PlanetData {
selected: boolean;
collisionTriggered: boolean;
startAngle?: number;
isBinary?: boolean;
binaryOffset?: number;
binarySpeed?: number;
}


Expand All @@ -54,6 +57,9 @@ const EnhancedPlanet = forwardRef<Mesh, EnhancedPlanetProps>(({
moons,
logoTexturePath,
startAngle = 0,
isBinary,
binaryOffset,
binarySpeed,
}, ref) => {
const atmosphereRef = useRef<Mesh>(null);
const [hovered, setHovered] = useState(false);
Expand Down Expand Up @@ -90,17 +96,37 @@ const EnhancedPlanet = forwardRef<Mesh, EnhancedPlanetProps>(({

useFrame(({ clock }) => {
const elapsed = clock.getElapsedTime();
if (meshRef.current) { // Update planet
const angle = elapsed * orbitSpeed + startAngle;
meshRef.current.position.x = orbitRadius * Math.cos(angle);
meshRef.current.position.z = orbitRadius * Math.sin(angle);
meshRef.current.rotation.y += rotationSpeed; // Planet rotation
if (meshRef.current) {
if (isBinary && binaryOffset !== undefined && binarySpeed !== undefined) {
// Calculate the binary orbit position
const binaryAngle = elapsed * binarySpeed;
const binaryX = Math.cos(binaryAngle) * binaryOffset;
const binaryZ = Math.sin(binaryAngle) * binaryOffset;

// Calculate the main orbit position
const orbitAngle = elapsed * orbitSpeed + startAngle;
const orbitX = orbitRadius * Math.cos(orbitAngle);
const orbitZ = orbitRadius * Math.sin(orbitAngle);

// Combine the positions
meshRef.current.position.x = orbitX + binaryX;
meshRef.current.position.z = orbitZ + binaryZ;
} else {
// Original single planet behavior
const angle = elapsed * orbitSpeed + startAngle;
meshRef.current.position.x = orbitRadius * Math.cos(angle);
meshRef.current.position.z = orbitRadius * Math.sin(angle);
}

meshRef.current.rotation.y += rotationSpeed;

// Update atmosphere and logo positions
if (atmosphereRef.current) {
atmosphereRef.current.position.copy(meshRef.current.position);
atmosphereRef.current.rotation.copy(meshRef.current.rotation);
}
if (logoRef.current) {
logoRef.current.rotation.y += 0.01; // Logo rotation speed
logoRef.current.rotation.y += 0.01;
}
}
});
Expand Down Expand Up @@ -158,7 +184,7 @@ const EnhancedPlanet = forwardRef<Mesh, EnhancedPlanetProps>(({
{/* Atmosphere layer */}
<mesh
ref={atmosphereRef}
scale={[1.18, 1.18, 1.18]}
scale={[1.225, 1.225, 1.225]}
>
<sphereGeometry args={[size, 64, 64]} />
<primitive object={atmosphereMaterial} attach="material" />
Expand Down
57 changes: 34 additions & 23 deletions warpgate/EnhancedPlanetGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export interface PlanetData {
moons?: MoonData[];
logoTexturePath?: string;
initialAngle?: number;
isBinary?: boolean;
binaryOffset?: number;
binarySpeed?: number;
}

interface ExplosionData {
Expand All @@ -68,7 +71,8 @@ const EnhancedPlanetGroup: React.FC<EnhancedPlanetGroupProps> = ({ onSelectPlane
description: 'explore()',
orbitRadius: 2.33,
orbitSpeed: 0.775,
planetColor: '#B7D3F2',
startAngle: 0,
planetColor: '#C3F6EE',
size: 0.29,
rotationSpeed: 0.02,
moons: [
Expand All @@ -91,6 +95,7 @@ const EnhancedPlanetGroup: React.FC<EnhancedPlanetGroupProps> = ({ onSelectPlane
description: 'getPlaylists()',
orbitRadius: 2.33,
orbitSpeed: 0.775,
startAngle: (Math.PI),
planetColor: '#F9B9F2',
rings: [
{ color: 'white', innerScale: 1.2, outerScale: 1.5, inclination: Math.PI / 2 },
Expand All @@ -105,8 +110,8 @@ const EnhancedPlanetGroup: React.FC<EnhancedPlanetGroupProps> = ({ onSelectPlane
link: 'https://www.linkedin.com/in/ridwansharkar',
label: 'LinkedIn',
description: 'connect()',
orbitRadius: 3.6,
orbitSpeed: 0.4,
orbitRadius: 3.9,
orbitSpeed: 0.45,
planetColor: '#4FB8FF',
size: 0.37,
rotationSpeed: 0.01,
Expand All @@ -115,47 +120,53 @@ const EnhancedPlanetGroup: React.FC<EnhancedPlanetGroupProps> = ({ onSelectPlane
],
logoTexturePath: '/textures/LinkedIn_logo.svg',
},
// PLANET 3,25: BORROWED ORDER
// PLANET 3,25: BORROWED ORDER BINARY SYSTEM
{
position: [0, 0, 0],
link: 'https://ridwansharkar.github.io/Borrowed-Order/',
label: 'Borrowed Order',
description: 'visualize()',
orbitRadius: 6.3,
orbitRadius: 6,
orbitSpeed: 0.125,
startAngle: (2 * Math.PI) / 3,
planetColor: '#c7434d',
size: 0.24,
rotationSpeed: 0.03,
startAngle: (Math.PI),
planetColor: '#C89FD9',
size: 0.27,
rotationSpeed: 0.05,
rings: [
{ color: '#00FFFF', innerScale: 1.3, outerScale: 1.45, inclination: -Math.PI / 3 }
],
logoTexturePath: '/textures/BorrowedOrder_logo.svg',
isBinary: true,
binaryOffset: 0.5,
binarySpeed: 2.0,
},
// PLANET 3.5: Nutrimancer
// PLANET 3.5: Nutrimancer BINARY
{
position: [0, 0, 0], // Starting on the opposite side of the orbit
position: [0, 0, 0],
link: 'https://github.com/RidwanSharkar/The-Nutrimancers-Codex',
label: "The Nutrimancer's Codex - Vol. II",
description: 'unknown()',
orbitRadius: 6.3,
orbitRadius: 6,
orbitSpeed: 0.125,
startAngle: (4 * Math.PI) / 3,
planetColor: '#84DCC6', //85FFC7
startAngle: (Math.PI),
planetColor: '#84DCC6',
rings: [
{ color: '#7EE081', innerScale: 1.25, outerScale: 1.6, inclination: Math.PI / 4.5 },
],
size: 0.325,
size: 0.3,
rotationSpeed: 0.01,
logoTexturePath: '/textures/Nutrimancer_logo.svg',
isBinary: true,
binaryOffset: -0.5,
binarySpeed: 2.0,
},
// PLANET 3: GITHUB
{
position: [0, 0, 0],
link: 'https://github.com/RidwanSharkar',
label: 'GitHub',
description: 'collaborate()',
orbitRadius: 6.3,
orbitRadius: 6,
orbitSpeed: 0.125,
startAngle: 0,
planetColor: '#8980F5',
Expand All @@ -167,26 +178,26 @@ const EnhancedPlanetGroup: React.FC<EnhancedPlanetGroupProps> = ({ onSelectPlane
rotationSpeed: 0.010,
moons: [
{
orbitRadius: 1.05,
orbitRadius: 1.12,
orbitSpeed: 2.25,
size: 0.11,
moonColor: '#F9B9F2',
moonColor: '#D9C6E8',
link: 'https://github.com/RidwanSharkar/Predictive-Analysis-of-MMA-Fights',
label: 'Predictive Analysis',
},
{
orbitRadius: 1.35,
orbitRadius: 1.43,
orbitSpeed: 1.5,
size: 0.1625,
moonColor: '#FFAAEE',
moonColor: '#F9B9F2',
link: 'https://github.com/RidwanSharkar/Pharmacological-Compound-Classifier',
label: 'Compound Classifier',
},
{
orbitRadius: 1.67,
orbitRadius: 1.76,
orbitSpeed: 2.2,
size: 0.13,
moonColor: '#D295BF',
size: 0.12,
moonColor: '#4FB8FF',
link: 'https://github.com/RidwanSharkar/Arbitrage-Better',
label: 'MMA Arbitrager',
},
Expand Down
14 changes: 8 additions & 6 deletions warpgate/Exoplanet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const Exoplanet: React.FC<ExoplanetProps> = ({ onRemove }) => {

// Constants for simulation
const SPAWN_RADIUS = 50;
const HYPERBOLIC_THRESHOLD = 40; // GRAVITY INFLUENCE
const HYPERBOLIC_THRESHOLD = 35; // GRAVITY INFLUENCE
const MIN_DISTANCE = 1.8; // ACTUAL COLLSION SIZE
const BASE_GRAVITY_STRENGTH = 0.15; // GRAVITY STRENGTH
const CLOSE_APPROACH_THRESHOLD = 2.3; // APPROACH THRESHOLD
const BASE_GRAVITY_STRENGTH = 0.17; // GRAVITY STRENGTH
const CLOSE_APPROACH_THRESHOLD = 2.2; // APPROACH THRESHOLD

const targetPoint = useMemo(() => {
const radius = Math.random() * 10; // COLLISION PLANE
Expand Down Expand Up @@ -73,6 +73,7 @@ const Exoplanet: React.FC<ExoplanetProps> = ({ onRemove }) => {
const [opacity, setOpacity] = useState(1);
const [showExplosion, setShowExplosion] = useState(false);
const [collisionPoint, setCollisionPoint] = useState<Vector3 | null>(null);
const [isVisible, setIsVisible] = useState(true);

// FADE OUT TIMER
useEffect(() => {
Expand All @@ -97,12 +98,13 @@ const Exoplanet: React.FC<ExoplanetProps> = ({ onRemove }) => {
const distanceToSun = meshRef.current.position.length();

// Check for collision with sun
if (distanceToSun < MIN_DISTANCE) {
if (distanceToSun < MIN_DISTANCE && isVisible) {
setCollisionPoint(meshRef.current.position.clone());
setShowExplosion(true);
setIsVisible(false);
setTimeout(() => {
onRemove();
}, 2000); // 1.5 seconds matching explosion duration
}, 3000);
return;
}

Expand All @@ -127,7 +129,7 @@ const Exoplanet: React.FC<ExoplanetProps> = ({ onRemove }) => {

return (
<group>
<mesh ref={meshRef}>
<mesh ref={meshRef} visible={isVisible}>
<sphereGeometry args={[size, 32, 32]} />
<meshStandardMaterial color={new Color(color)} transparent opacity={opacity} />
</mesh>
Expand Down
4 changes: 2 additions & 2 deletions warpgate/Sun.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface SunProps {
const Sun = forwardRef<Mesh, SunProps>(({
size = 1.10,
color = "#FDB813",
glowIntensity = 0.2,
glowIntensity = 0.35,
rotationSpeed = 0.001,
emissiveIntensity = 0.25,
}, ref) => {
Expand Down Expand Up @@ -91,7 +91,7 @@ const Sun = forwardRef<Mesh, SunProps>(({
color={color}
intensity={1.25}
distance={2000}
decay={0.7}
decay={0.3}
/>


Expand Down

0 comments on commit 06441fb

Please sign in to comment.