Skip to content

Add more control like (key rotation, dragging, zooming, and moving). #4

@osamasrour

Description

@osamasrour

Feature Request: Enhanced Viewer Controls

Summary

Add interactive viewport controls (keyboard rotation, mouse dragging, zooming, and panning) to allow for better inspection of the rendered OBJ models.

Proposed Features

1. Keyboard Rotation

Enable manual rotation using the keyboard to allow users to pause and inspect specific angles.

  • Keys: Arrow keys or WASD.
  • Behavior: Left/Right rotates around the Y-axis; Up/Down rotates around the X-axis.

2. Mouse Orbit (Dragging)

Implement rotation based on mouse movement when clicking and dragging.

  • Control: Left Click + Drag.
  • Behavior: Calculate the delta between mouse positions to rotate the model proportionally.

3. Zooming

Allow the user to move the camera closer or further away to inspect mesh details.

  • Control: Mouse Scroll Wheel or + / - keys.
  • Behavior: Scale the projection or modify the Z-translation of the model.

4. Panning (Moving)

Allow shifting the model's position within the 2D screen space.

  • Control: Right Click + Drag or Shift + Arrow Keys.
  • Behavior: Translate the model along the X and Y axes.

Why this is needed

Currently, the model rotates automatically, which makes it difficult to inspect specific vertices or faces. Adding manual controls provides a much more professional and user-friendly experience for 3D model viewing.

Implementation Suggestions

Since the project already uses an angle variable for rotation within the main loop, the rotation logic can be easily moved into the SDL_KEYDOWN or SDL_MOUSEMOTION event cases:

// Example snippet for event handler
while(SDL_PollEvent(&event)){
    if(event.type == SDL_KEYDOWN){
        switch(event.key.keysym.scancode){
            case SDL_SCANCODE_LEFT:
                angle -= 0.1f;
                break;
            case SDL_SCANCODE_RIGHT:
                angle += 0.1f;
                break;
            // ... other keys
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions