FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • How do splines work?loremIpsum1771
    I've been beginning to work with different kinds of splines (e.g. Bezier, Hermite, B-splines) in some of my work with computer graphics and I am trying to get a grasp of how they work (mathematically and programmatically). I know that generally (at least for cubic splines), you will have 4 control points that influence the position of points along an interpolated line. For example, with Bezier curves (as far as I understand), there can be two end points where the line will begin and terminate an
     

How do splines work?

I've been beginning to work with different kinds of splines (e.g. Bezier, Hermite, B-splines) in some of my work with computer graphics and I am trying to get a grasp of how they work (mathematically and programmatically). I know that generally (at least for cubic splines), you will have 4 control points that influence the position of points along an interpolated line. For example, with Bezier curves (as far as I understand), there can be two end points where the line will begin and terminate and two control points that influence the direction of the line.

I've been programming Bezier, Hermite, and B-Splines (in javascript on an html5 canvas) and what I don't understand is how to choose these 4 points in order to see a specific curve rendered on the screen. So far, I have only been able to render at least part of a curve by randomly playing around with different numbers for each point.

This is one of the many questions I have about the inner workings of splines so could someone provide an overview on how they work and how they can be programmed (most of the examples online are more theoretical and rather unspecific)?

  • ✇Recent Questions - Game Development Stack Exchange
  • Pan orthographic non-axis-aligned cameraThe Bic Pen
    I'm trying to create a panning control for a camera in bevy, but I can't seem to get the panning logic right when the camera is rotated. It works fine if the camera transform is directly facing the XY plane. This works with any axis as the "up" direction: Transform::from_xyz(0., 0., 1.).looking_at(Vec3::ZERO, Vec3::X) But, it doesn't move correctly when the camera isn't aligned to the plane, like so: Transform::from_xyz(1., -2., 2.).looking_at(Vec3::ZERO, Vec3::Z) I want the camera to pan over
     

Pan orthographic non-axis-aligned camera

I'm trying to create a panning control for a camera in bevy, but I can't seem to get the panning logic right when the camera is rotated. It works fine if the camera transform is directly facing the XY plane. This works with any axis as the "up" direction:

Transform::from_xyz(0., 0., 1.).looking_at(Vec3::ZERO, Vec3::X)

But, it doesn't move correctly when the camera isn't aligned to the plane, like so:

Transform::from_xyz(1., -2., 2.).looking_at(Vec3::ZERO, Vec3::Z)

I want the camera to pan over the XY plane at a fixed Z height. How can I convert this 2D implementation to a proper 3D implementation?

Here's the pseudocode for my current logic, for those not familiar with bevy:

Vec2 delta_mouse = get_mouse_movement_since_last_frame();
Angle camera_rotation = camera.get_rotation_axis_and_angle().angle;
Vec2 rotation_mat = { x: cos(camera_rotation), y: sin(camera_rotation) };
Vec2 rotated_delta_mouse = {
    x: delta_mouse.x * rotation_mat.x - delta_mouse.y * rotation_mat.y,
    y: delta_mouse.y * rotation_mat.x + delta_mouse.x * rotation_mat.y
};
camera.translation += rotated_delta_mouse;

And the full rust code I am using now:

fn drag_camera(
    input: Res<ButtonInput<MouseButton>>,
    mut camera_query: Query<&mut Transform, With<Camera>>,
    window_query: Query<&Window>,
    mut ev_motion: EventReader<MouseMotion>,
    camera_info: Res<CameraSettings>,
) {
    let pan_button = MouseButton::Left;
    if !input.pressed(pan_button) {
        return;
    }
    let mut pan = Vec2::ZERO;
    for ev in ev_motion.read() {
        pan += ev.delta;
    }
    let mut scale_factor = camera_info.zoom_scale * 2.;
    let window = window_query.single();
    scale_factor /= window.resolution.physical_height() as f32;

    let mut transform = camera_query.single_mut();
    let rotation_angle = transform.rotation.to_axis_angle().1;
    let pan_rotated = pan.rotate(Vec2::from_angle(rotation_angle));

    transform.translation.x -= pan_rotated.x * scale_factor;
    transform.translation.y += pan_rotated.y * scale_factor;
}
  • ✇Recent Questions - Game Development Stack Exchange
  • Orbit Camera In vulkanwij
    I've been having trouble trying to make a solidworks style Orbit Camera, nothing I do seems to work even though apparently it should (I've tried multiple methods and this seems to be the most promising). I have a camera struct defined as such Camera :: struct { pos:vec3 = .{0,0,1}; // 1 target:vec3 = .{0,0,0}; up:vec3 = .{0,0,1}; right:vec3 = .{1,0,0}; // zoom:float = 1; Tmat:mat4 = IDENTITY; // Translation Rmat:mat4 = IDENTITY; // Rotation Pmat:mat4 = IDENTITY;
     

Orbit Camera In vulkan

I've been having trouble trying to make a solidworks style Orbit Camera, nothing I do seems to work even though apparently it should (I've tried multiple methods and this seems to be the most promising).

I have a camera struct defined as such

Camera :: struct {
    pos:vec3 = .{0,0,1}; // 1
    target:vec3 = .{0,0,0};

    up:vec3 = .{0,0,1};
    right:vec3 = .{1,0,0};
    // zoom:float = 1;

    Tmat:mat4 = IDENTITY; // Translation
    Rmat:mat4 = IDENTITY; // Rotation
    Pmat:mat4 = IDENTITY; // Pivot matrix
    
    view:mat4 = IDENTITY;
    viewMat:mat4 = IDENTITY; // really inverse view mat

    lastposx:float;
    lastposy:float;
}

my rotate camera function is defined as such

rotate_cam :: (r:fwdpp_r,cam:*Camera,x:float,y:float) {
    using cam;
    rotation_origin := target;

    dx := TAU / r.pipeline.Extent.width;
    dy := PI / r.pipeline.Extent.height;
    r_x := (lastposx - x) * dx;
    r_y := (lastposy - y) * dy;
    lastposx = x;
    lastposy = y;
    rotx:Quaternion = .{r_x,0,0,1};
    roty:Quaternion = .{0,0,r_y,1};

    camDir := normalize(pos - target);

    right = xx normalize(cross(up,camDir));
    up = xx normalize(cross(camDir,right));

    rq := rotx * roty;

    Rmat = rotate(Rmat,rq);


    updateViewMatrix(cam);
}

with rotate being

rotate :: (q: Quaternion) -> Matrix4 {
    m: Matrix4;



    xs := q.x * 2;
    ys := q.y * 2;
    zs := q.z * 2;

    wx := q.w * xs;
    wy := q.w * ys;
    wz := q.w * zs;

    _xx := q.x * xs;
    xy := q.x * ys;
    xz := q.x * zs;

    yy := q.y * ys;
    yz := q.y * zs;
    zz := q.z * zs;

    m._11 = 1.0 - (yy + zz);
    m._12 = xy - wz;
    m._13 = xz + wy;

    m._21 = xy + wz;
    m._22 = 1.0 - (_xx + zz);
    m._23 = yz - wx;

    m._31 = xz - wy;
    m._32 = yz + wx;
    m._33 = 1.0 - (_xx + yy);
    
    m._44 = 1;

    return m;
}

update_view matrix being

updateViewMatrix :: (cam:*Camera) {
    using cam;
    Pmat = translate(IDENTITY,target);
    viewMat = multiply(TO_VULKAN_COORDS_MATRIX,inverse(Pmat) * Rmat * Pmat * Tmat);
    view = inverse(viewMat);
}
TO_VULKAN_COORDS_MATRIX :: Matrix4.{
    0, -1,  0,  0,
    0,  0, -1,  0,
    1,  0,  0,  0,
    0,  0,  0,  1,
};

This produces this result

❌
❌