pseudo 3D camera turning html canvas javascript

I am trying to learn to make 3D games in JavaScript using HTML 2D canvas. I was following this post about it and I made a simple scene that you can move around in.

What I need help with is figuring out how to make the effect of the player turning their head, to look side to side and behind them.

Here is what I have:

Codepen link

Code (also on codepen)

html:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3d test</title>
</head>
<body>
    <canvas id="canv"></canvas>
</body>
</html>

javascript

//use arrow keys to move around

var canvas = document.getElementById("canv");
var c = canvas.getContext("2d");

canvas.width = canvas.height = 800;

var crateImg = new Image();

class Entity {
    constructor(x, y, z, w, h) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.w = w;
        this.h = h;
        this.rx = 0;
        this.ry = 0;
        this.rs = 0;
    }
    render() {
        //c.fillStyle = 'red';
        //c.fillRect(this.rx, this.ry, this.rs*this.w, this.rs*this.h);
        c.drawImage(crateImg, this.rx, this.ry, this.rs*this.w, this.rs*this.h);
    }
    update() {
        //project to 3d
        this.rs = 400/(400+this.z);
        this.rx = ((this.x*this.rs) + 400);
        this.ry = (this.y*this.rs) + 400;


        //move
        this.x += camera.xSpeed;
        this.y += camera.ySpeed;
        this.z += camera.zSpeed;
    }
}

var camera = {
    xSpeed: 0,
    ySpeed: 0,
    zSpeed: 0,
}

var entities = ();

function random(min, max) {
    return Math.floor(Math.random() * (max - min) + min);
}

window.onload = function() {
    start();
    update();
}

function start() {
    crateImg.src = "https://i.imgur.com/O9ForWS_d.webp?maxwidth=760&amp;fidelity=grand";
    for(let i = 0; i < 100; i++) {
        entities.push(new Entity(random(-800, 800), 0, i*10, 50, 50));
    }
}

function render() {
    //fill background
    c.fillStyle = 'skyblue';
    c.fillRect(0, 0, 800, 800);
    //draw flooor
    c.fillStyle = 'green';
    c.fillRect(0, 400, 800, 400);
    //draw entities
    for(let i = 0; i < entities.length; i++) {
        if(entities(i).z > -400) {
            entities(i).render();
        }
    }
}

function update() {
    //updatre entities
    for(let i = 0; i < entities.length; i++) {
        entities(i).update();
    }
    entities.sort(function(i, i2) {
        return i2.z - i.z;
    })
    //redraw current frame
    render();
    requestAnimationFrame(update);
}


function keyDown(e) {
    switch(e.keyCode) {
        case 39:
            camera.xSpeed = -5;
            break;
        case 37:
            camera.xSpeed = 5;
            break;
        case 38:
            camera.zSpeed = -5;
            break;
        case 40:
            camera.zSpeed = 5;
            break;
    }
}

function keyUp(e) {
    switch(e.keyCode) {
        case 39:
        case 37:
            camera.xSpeed = 0;
            break;
        case 38:
        case 40:
            camera.zSpeed = 0;
            break;
    }
}

document.onkeydown = keyDown;
document.onkeyup = keyUp;
```

adb – Turning on “show pointer” breaks mirrored screen. How to turn off without phone screen

I am trying to help a friend who’s screen broke on their Huawei P30. The screen is dead-dead. No touch, no light, nothing.

So I tried to connect an external screen to it, an voila, I have a screen. I even have a mouse and keyboard working. However, I want to copy the contents of the phone onto the computer, and nothing is showing up on the computer when I plug it in. So I tried to get ADB to help me.

ADB is not trusted, or something along those lines. So I go back to the screen, and turn on developer mode, and try to change settings to hopefully bypass the notification asking to give permission. Nothing works, I keep trying new settings.

This is where I mess up. Apparently there is a bug or something, because when you turn on (and I have no idea why I did this) “Show Pointer” the external display goes black with a grey bar at the top theoretically showing the pointer X and Y coordinates, etc.

If I reboot the device I see the home screen for 0.5 to 3 seconds before it reverts back to the black screen. If in this time, I click on the settings icon, it immediately goes to black.

Question: Is there a way, without access to the screen of a device to:

  1. get ADB to work without it been an authorized device (I’m guessing not), or
  2. turn off pointer location somehow using ADB or similar method, or
  3. navigate the menus of the phone with a keyboard only, no mouse, no clicking, just keystrokes, so I can disable this blind (using another phone or video to know how many times to press down, for example)?

Any advice at all would be great. Since they already have a new phone, I don’t want to have to pay to replace the screen, but that is last resort (which I hope would work).

gnome – HDMI turning on and off on Dell Inspiron 3584 [Ubuntu 20.04]

I’m having some problems while using my TV and Notebook Dell Inspiron 3584 together using the Join Display’s Mode. After some time the TV image goes off, and after a few minutes comes back. I did some tail -f /var/log to see what appears in the log when it happens and I saw these messages:

When TV image goes off:

Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): EDID vendor "AUO", prod id 29164
Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Printing DDC gathered Modelines:
Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   76.30  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (49.0 kHz eP)
Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   61.04  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (39.2 kHz e)
Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): EDID vendor "AUO", prod id 29164
Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Printing DDC gathered Modelines:
Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   76.30  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (49.0 kHz eP)
Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   61.04  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (39.2 kHz e)
Jun  5 09:26:38 Inspiron-3584 rtkit-daemon(968): Supervising 3 threads of 1 processes of 1 users.
Jun  5 09:26:38 Inspiron-3584 rtkit-daemon(968): Successfully made thread 7231 of process 1873 owned by '1000' RT at priority 5.
Jun  5 09:26:38 Inspiron-3584 rtkit-daemon(968): Supervising 4 threads of 1 processes of 1 users.
Jun  5 09:26:38 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Allocate new frame buffer 1366x768 stride
Jun  5 09:26:38 Inspiron-3584 rtkit-daemon(968): Supervising 3 threads of 1 processes of 1 users.
Jun  5 09:26:38 Inspiron-3584 rtkit-daemon(968): Successfully made thread 7232 of process 1873 owned by '1000' RT at priority 5.
Jun  5 09:26:38 Inspiron-3584 rtkit-daemon(968): Supervising 4 threads of 1 processes of 1 users.
Jun  5 09:26:38 Inspiron-3584 gsd-media-keys(2279): Unable to get default sink
Jun  5 09:26:39 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): EDID vendor "AUO", prod id 29164
Jun  5 09:26:39 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Printing DDC gathered Modelines:
Jun  5 09:26:39 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   76.30  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (49.0 kHz eP)
Jun  5 09:26:39 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   61.04  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (39.2 kHz e) 

When the image comes back on:

Jun  5 09:31:06 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): EDID vendor "AUO", prod id 29164
Jun  5 09:31:06 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Printing DDC gathered Modelines:
Jun  5 09:31:06 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   76.30  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (49.0 kHz eP)
Jun  5 09:31:06 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   61.04  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (39.2 kHz e)
Jun  5 09:31:06 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (--) modeset(0): HDMI max TMDS frequency 225000KHz
Jun  5 09:31:06 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Allocate new frame buffer 3286x1080 stride
Jun  5 09:31:06 Inspiron-3584 rtkit-daemon(968): Supervising 3 threads of 1 processes of 1 users.
Jun  5 09:31:06 Inspiron-3584 rtkit-daemon(968): Successfully made thread 7396 of process 1873 owned by '1000' RT at priority 5.
Jun  5 09:31:06 Inspiron-3584 rtkit-daemon(968): Supervising 4 threads of 1 processes of 1 users.
Jun  5 09:31:06 Inspiron-3584 rtkit-daemon(968): Supervising 3 threads of 1 processes of 1 users.
Jun  5 09:31:06 Inspiron-3584 rtkit-daemon(968): Successfully made thread 7397 of process 1873 owned by '1000' RT at priority 5.
Jun  5 09:31:06 Inspiron-3584 rtkit-daemon(968): Supervising 4 threads of 1 processes of 1 users.
Jun  5 09:31:07 Inspiron-3584 gsd-media-keys(2279): Unable to get default sink
Jun  5 09:31:07 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): EDID vendor "AUO", prod id 29164
Jun  5 09:31:07 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Printing DDC gathered Modelines:
Jun  5 09:31:07 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   76.30  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (49.0 kHz eP)
Jun  5 09:31:07 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (II) modeset(0): Modeline "1366x768"x0.0   61.04  1366 1374 1384 1558  768 771 772 816 +hsync -vsync (39.2 kHz e)
Jun  5 09:31:07 Inspiron-3584 /usr/lib/gdm3/gdm-x-session(1947): (--) modeset(0): HDMI max TMDS frequency 225000KHz
Jun  5 09:31:07 Inspiron-3584 colord(1490): failed to get session (pid 2271): No data available
  1. OS: Ubuntu 20.04.
  2. Notebook: Dell Inspiron 3584
  3. TV: Philips 39pfl4707g/78
  4. HDMI Cable: Working on PS4 and Windows.

Ty.

grid – Overlapping div in left side when turning off the collapse on the left sidebar

I built a dashboard that contains sidebar with collapse. When I try to put chartjs and make it display:grid, it turns out it is overlapping the right side when turning of the collapse.

Here is my html code:

<div style="grid-template-rows: auto;">
    <div class="line">
        <canvas id="myChart"></canvas>
    </div>
    <div class="line">
        <canvas id="myChart"></canvas>
    </div>
</div>
<div class="pie">   
    <canvas id="pieChart"></canvas>
</div>

css code:

    .line {
        margin-top: 3rem;
        background: #fff;
        width: 100%;
        height: 23.9vh;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);
    }

    
    .pie {
        margin-top: 3rem;
        background: #fff;
        width: 100%;
        height: 50vh;
        box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);
    }

I have same code with my cards but I don’t know why my charts becomes like this.

enter image description here

enter image description here

UPDATE: I put `position:fixed in my canvas of pie chart and it works but the pie chart gets smaller when turning off the collapse.

unity – Why does only the sound for turning off the flashlight play?

This script is supposed to play a sound when I turn on the flashlight sprite and a different sound when I turn it off, but for some reason it’s only playing the second sound.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class flashlightonoffsound : MonoBehaviour
{
    public static bool flashlightisoff = false;

    public AudioSource flashlightsound1;

    public AudioSource flashlightsound2;
  
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (flashlightisoff)
            {
                flashlightsound1.Play();
            }
            else
            {
                flashlightsound2.Play();
            }
        }

    }
}

unity – why isnt this for turning a flashlight on and off working?

i dont know if this matters but I’m using unity 2D. the code only turns the flashlight off and not back on.

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class flashlightonoff : MonoBehaviour
{
public static bool flashlightisoff = false;

public GameObject Flashlight;

void Start()
{
    Flashlight.SetActive(true);
}

void Update()
{
    if (Input.GetKeyDown(KeyCode.E))
    {
        if (flashlightisoff)
        {
            ON();
        }
        else
        {
            OFF();
        }
    }
    
}

void ON()
{
    Flashlight.SetActive(true);
    flashlightisoff = false;
}

void OFF()
{
    Flashlight.SetActive(false);
    flashlightisoff = true;
}

}`

Windows 7. It keeps turning off as I added bits and wuauserv and wuauserv service is still turning off

it’s me, Mich. I also had a Windows update problem. The problem is: wuauserv service keeps turning off if I tried turning it on. Here is my PCs info:

Windows 7 SP1.

Can I have any solutions?

https://vimeo.com/manage/videos/546572190

Please, mods. Don’t delete this. Look what is the Vimeo is.

calls – Ringtone volume keeps turning off

Using Samsung Galaxy A41 on Android 10, my ringtone volume is automatically resetting to 0 all the time – which means that I’m missing phone calls. I don’t have any apps installed that should be doing this automatically.

What could be the cause and how can I debug this?

Nikon D3200 turning Flash off in P, S, A, M mode

Auto mode is auto everything, exposure and flash and ISO and white balance and color profile, everything. Cannot turn auto features off, so no choice of selecting anything. Auto is auto.

In M,A,S,P modes, the user controls these things, as desired. Some individual auto features can be chosen, but they can also be turned off, to select specific values to use.

There is no Flash Off option in M,A,S,P modes. Flash is auto in Auto mode, and Auto mode needs the Flash Off option.

But the way M,A,S,P works is that if you don’t want flash in M,A,S,P, then you simply do not turn the flash on, or simply do not open the internal flash door. Then flash will be off. This is the photographers choice to do, and how it works.

The camera manual instructions for flash with M,A,S,P modes starts with “turn the flash on, or open the internal door”.
The instructions for Auto mode says “don’t open flash”, the flash will be automatically used when deemed needed (but Flash Off will disallow it in places where flash is prohibited or objectionable).

There is a 1/60 second Minimum Shutter Speed With Flash in A and P modes. Indoors (dimmer light), if you want a shutter speed slower than 1/60 second, you have two options. Use camera M or S mode, and set any slower shutter speed directly. Or in A or P modes, you can use flash sync options of Slow sync or Rear Curtain sync, and that will use the slower shutter speed actually metered.

In M and S modes, shutter speed is what you set it to be.
In A and P modes, shutter speed is metered, but the 1/60 second Minimum applies, unless Slow sync.

In Auto mode, the flash and shutter speed will remain completely auto, and Flash Off is the only choice to disallow it. Flash Off is only needed by Auto mode.

For slower shutter speeds:

Example, with flash turned off, maybe the dim scene meters 1/4 second.

(speaking of Nikon).

You turn on the flash, and in A or P modes, the shutter jumps to 1/60 second Minimum Shutter With Flash, because 1/4 is too slow to handhold. This is NOT a value metered from ambient, ambient will be underexposed. But you are using flash instead, you normally don’t need 1/4 second.

In A or P modes, if you set Slow Sync (or Rear Curtain sync, which includes Slow Sync), then the original metered 1/4 second will be used (whatever ambient meters will be used).

Or you can use camera M or S mode and set any slow shutter speed you desire.

Shutter speed does not affect the flash exposure, but it will seriously affect the ambient exposure. Overall photo exposure is the sum of ambient plus flash, so we gain added control when we realize that flash photos are a “double exposure” combining the two exposures. Indoors, ambient level is often insignificant, but is the overwhelming factor for fill flash in bright sun.

More expensive Nikon models have an E2 menu where this Minimum Shutter Speed With Flash can be chosen (any speed not faster than 1/60 second).

If you want a shutter speed faster than 1/60 second, then either go into a brighter light scene that will meter higher in A or P modes, or use camera M or S mode to set what you want.

But in M,A,S,P modes, you enable the flash on when you want flash to fire, and don’t when you don’t. If the flash is “on”, it will fire. It is not enabled automatically except in Auto mode.

1/200 second is that camera’s Maximum Sync Speed for flash. That value is typical and most common. It cannot be faster to properly sync flash. Some camera’s and speedlights offer a HSS flash mode (converts instantaneous flash to be on continuously for awhile, thus no sync requirement) to allow any faster shutter speed. Mainly, the purpose is that this also allows a wide open lens with flash outdoors. However, HSS has serious disadvantages of allowing only around 20% flash power, and HSS also bypasses the speedlights motion stopping capabilities.

c# – Playerbody is turning, but not moving in direction turned

So, I have a simple WASD script, and I’ve added a part so when Mouse X is moved, the playerBody (character) rotates in that direction, so, when W is pressed (to go forward) the player does not move in the direction turned, but it moves in the same direction. Although the playerBody has turned, the player still moves in the same direction…. why?

using UnityEngine;
using System.Collections;

// This script moves the character controller forward
// and sideways based on the arrow keys.
// It also jumps when pressing space.
// Make sure to attach a character controller to the same game object.
// It is recommended that you make only one call to Move or SimpleMove per frame.

public class Move : MonoBehaviour
{
    CharacterController characterController;

    public float speed = 6.0f;
    public float jumpSpeed = 8.0f;
    public float gravity = 20.0f;
    public Transform charBody;
    private Vector3 moveDirection = Vector3.zero;

    void Start()
    {
        characterController = GetComponent<CharacterController>();
    }

    void Update()
    {
        if (characterController.isGrounded)
        {
            // We are grounded, so recalculate
            // move direction directly from axes

            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
            moveDirection *= speed;

            if (Input.GetButton("Jump"))
            {
                moveDirection.y = jumpSpeed;
            }
        }

        // Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
        // when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
        // as an acceleration (ms^-2)
        moveDirection.y -= gravity * Time.deltaTime;

        // Move the controller
        characterController.Move(moveDirection * Time.deltaTime);

        float MOUSEY = Input.GetAxis("Mouse Y") * speed * Time.deltaTime;
        float MOUSEX = Input.GetAxis("Mouse X") * speed * Time.deltaTime;

        charBody.Rotate(Vector3.up * MOUSEX);

        


    }
}

Thanks