Left: 3D cube with neon cyberpunk theme rendered in OpenGL | Right: Real-time hand tracking with MediaPipe โ 21 landmark detection, neon cyan skeleton, pink joint dots
https://github.com/mohitr2111/3dCubeControl/raw/main/ScreenShot/2.mp4
Full demo โ rotating, zooming and controlling the 3D cube using bare hand gestures at 32 FPS
3dCubeControl is a real-time interactive application that lets you manipulate a 3D cube using nothing but your hand. No controller, no mouse, no touch โ just your hand in front of a webcam.
Built on top of Google's MediaPipe Tasks API for hand landmark detection and OpenGL for 3D rendering, the system detects 21 precise hand landmarks per frame and translates your hand movements into smooth 3D transformations โ rotation on X and Y axes and zoom โ all at real-time speed.
The UI features a dark neon / cyberpunk theme โ deep navy background, vivid neon-colored cube faces, bright white edges, and a neon skeleton hand overlay.
| Feature | Description |
|---|---|
| ๐๏ธ 21-Point Hand Tracking | Full hand skeleton with MediaPipe Tasks API |
| ๐ฒ Real-Time 3D Rendering | OpenGL-powered cube with Phong lighting |
| ๐ Multi-Axis Rotation | Rotate on X and Y axes simultaneously |
| ๐ Pinch-to-Zoom | Smooth zoom with pinch gesture |
| ๐ค Idle Auto-Rotation | Cube slowly rotates when no hand detected |
| ๐จ Neon Cyberpunk Theme | Dark navy bg, vivid neon cube faces, white edges |
| ๐ Live HUD Overlay | Real-time FPS, Rotation X/Y, Zoom on screen |
| โก Smooth Gesture Filtering | Moving average + exponential smoothing |
| ๐ Auto Model Download | MediaPipe model auto-downloads on first run |
| โจ๏ธ Keyboard Shortcuts | Reset, Quit via keyboard |
| Gesture | Action |
|---|---|
| ๐๏ธ Open hand + move Left / Right | Rotate cube on Y-axis |
| ๐๏ธ Open hand + move Up / Down | Rotate cube on X-axis |
| ๐ค Pinch (Thumb + Index closer) | Zoom In |
| ๐ค Pinch (Thumb + Index apart) | Zoom Out |
| โ Close hand / Remove hand | Pause โ cube enters idle rotation |
| Key | Action |
|---|---|
R |
Reset cube to default position |
Q or ESC |
Quit application |
3dCubeControl/
โ
โโโ main.py # Main application (all logic)
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ .gitignore # Git ignore rules
โ
โโโ ScreenShot/
โ โโโ 1.png # Live demo screenshot
โ โโโ 2.mp4 # Live demo screen recording
โ
โโโ hand_landmarker.task # MediaPipe model (auto-downloaded, gitignored)
Webcam Frame
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ OpenCV Capture โ 640ร480, flipped (mirror)
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ MediaPipe Tasks โ Detects 21 hand landmarks per frame
โ HandLandmarker โ VIDEO mode @ ~30fps
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ GestureController โ Palm center โ rotation delta
โ โ Pinch distance โ zoom delta
โ โ Exponential smoothing applied
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ OpenGL Renderer โ 800ร600 window
โ (Pygame + OpenGL) โ Phong lighting (2 lights)
โ โ 6-face colored cube + grid
โโโโโโโโโโโโโโโโโโโโโโโ
| Element | Color / Style |
|---|---|
| ๐ Background | Deep dark navy (0.04, 0.04, 0.10) |
| ๐ฅ Cube Front | Neon Red (1.0, 0.08, 0.08) |
| ๐ฉ Cube Back | Neon Green (0.0, 1.0, 0.3) |
| ๐ฆ Cube Top | Electric Blue (0.0, 0.5, 1.0) |
| ๐จ Cube Bottom | Neon Yellow (1.0, 0.95, 0.0) |
| ๐ช Cube Right | Neon Purple (0.8, 0.0, 1.0) |
| ๐ฉต Cube Left | Neon Cyan (0.0, 1.0, 0.9) |
| โฌ Cube Edges | Bright White โ 2.5px |
| ๐ท Grid | Dark Neon Blue |
| ๐ซ Hand Skeleton | Neon Cyan lines |
| ๐ Hand Joints | Neon Pink filled dots |
Config โ All tunable constants (resolution, sensitivity, zoom limits)
HandTracker โ MediaPipe Tasks API wrapper โ detects landmarks, draws skeleton
GestureController โ Converts landmark positions to rotation/zoom deltas with smoothing
Renderer3D โ OpenGL cube + grid drawing, Pygame window management
App โ Main loop โ ties everything together, HUD overlay
class Config:
WEBCAM_WIDTH = 640 # Webcam resolution
WEBCAM_HEIGHT = 480
RENDER_WIDTH = 800 # 3D window size
RENDER_HEIGHT = 600
ROTATION_SENSITIVITY = 0.3 # Higher = faster rotation
ZOOM_SENSITIVITY = 0.015 # Higher = faster zoom
smoothing_factor_size = 0.4 # Lower = more responsive, higher = smoother
ZOOM_MIN = -15.0 # Max zoom out
ZOOM_MAX = -2.0 # Max zoom in
ZOOM_DEFAULT = -6.0 # Starting zoom levelThe gesture controller uses a two-stage smoothing pipeline:
- Exponential Moving Average โ blends current delta with previous smooth value
smooth_dx = alpha * delta[0] + (1 - alpha) * smooth_dx- Moving Average Window โ averages last 5 frames for stability
history_x = deque(maxlen=5)
rotation_y += mean(history_x) * ROTATION_SENSITIVITY- Python 3.10+
- Webcam (built-in or external)
- OS: Windows / macOS / Linux
git clone https://github.com/mohitr2111/3dCubeControl.git
cd 3dCubeControl# Create
python3 -m venv venv
# Activate (macOS/Linux)
source venv/bin/activate
# Activate (Windows)
venv\Scripts\activatepip install -r requirements.txtpython3 main.pyOn first run, the MediaPipe hand landmarker model (~7.5 MB) downloads automatically.
[INFO] Starting 3D Cube Control... Press 'q' to quit.
Downloading hand landmark model...
Model downloaded!
Webcam opened successfully!
Hand tracker ready!
opencv-python # Webcam capture + image processing
mediapipe # Hand landmark detection (Tasks API)
numpy # Math operations for 3D transformations
pygame # Window + event management
PyOpenGL # 3D graphics rendering
PyOpenGL_accelerate # OpenGL speed boost (optional)
# In Config class
ROTATION_SENSITIVITY = 0.3 # Increase for faster rotation
ZOOM_SENSITIVITY = 0.015 # Increase for faster zoom
smoothing_factor_size = 0.4 # Lower = more snappy, higher = smoother# In draw_cube() โ faces list
# Format: (normal, [R, G, B], vertices)
# R, G, B values are 0.0 to 1.0
([0, 0, 1], [1.0, 0.08, 0.08], [...]), # Front โ change color here
([0, 0, -1], [0.0, 1.0, 0.3 ], [...]), # Back# In HandTracker.__init__()
options = vision.HandLandmarkerOptions(
min_hand_detection_confidence=0.5, # 0.0 to 1.0
min_hand_presence_confidence=0.5,
min_tracking_confidence=0.5,
)- Ensure webcam is not used by another app
- macOS: System Preferences โ Security & Privacy โ Camera โ enable Terminal/Python
- Windows: Settings โ Privacy โ Camera โ enable
- Ensure good lighting โ avoid very dark rooms
- Keep hand clearly visible, centered in frame
- Try reducing
min_hand_detection_confidenceto0.3
- Close other applications
- Reduce
WEBCAM_WIDTH/HEIGHTin Config - Ensure GPU drivers are updated for OpenGL
- Linux:
sudo apt-get install python3-opengl - Windows: Update GPU drivers
- Ensure virtual environment is activated
- Re-run:
pip install -r requirements.txt
| Metric | Value |
|---|---|
| Typical FPS | 30โ60 FPS |
| Hand Landmarks | 21 points per frame |
| Smoothing Window | 5 frames moving average |
| Webcam Resolution | 640 ร 480 |
| 3D Window | 800 ร 600 |
| Model Size | ~7.5 MB |
- Two-hand support โ separate control per hand
- Multiple 3D shapes (sphere, pyramid, custom
.objmodels) - Gesture recording and playback
- Color theme switcher via keyboard
- VR/AR mode integration
- Multi-object scene with hand collision
This project is licensed under the MIT License โ see the LICENSE file for details.
- Google MediaPipe โ Hand landmark detection
- OpenCV โ Real-time computer vision
- PyGame โ Window and event management
- PyOpenGL โ OpenGL Python bindings
Control reality with your hands. ๐๏ธโจ
Made with โค๏ธ by mohitr2111
