Moving Camera inside object

by cristianrodriguezcanto

HTML

<style>
         #top-camera
        {
            position: absolute;
            top:50px;
            left:10px;
            width: 1000px;
            height: 350px;
            clear: both;
            float: left;
        }
      #bottom-camera
        {
            position: absolute;
            top:420px;
            left:10px;
            width: 1000px;
            height: 400px;
            clear: both;
            float: left;
        }
    </style>
</head>

<body>
    <canvas id="top-camera"></canvas>
  <canvas id="bottom-camera" class="c"></canvas>
    <button id="forward" >forward</button>
    <button id="backward" >backward</button>
</body>

JavaScript

import {OrbitControls} from 'https://threejsfundamentals.org/threejs/resources/threejs/r119/examples/jsm/controls/OrbitControls.js';

const scene = new THREE.Scene();

var pointsLine1= [];
pointsLine1.push(new THREE.Vector3(-20, 0, 0));
pointsLine1.push(new THREE.Vector3(-5, 3, 0));
pointsLine1.push(new THREE.Vector3(-1, 1, 0));
pointsLine1.push(new THREE.Vector3(10, -1, 0));
pointsLine1.push(new THREE.Vector3(25, -15, 0));
var geometryLine = new THREE.BufferGeometry().setFromPoints(pointsLine1);
var line = new THREE.Line(geometryLine, new THREE.LineBasicMaterial({color: new THREE.Color("green")}))
scene.add(line);

var pointsLine1= [];
pointsLine1.push(new THREE.Vector3(-20, 0, 3));
pointsLine1.push(new THREE.Vector3(-5, 3, 3));
pointsLine1.push(new THREE.Vector3(-1, 1, 3));
pointsLine1.push(new THREE.Vector3(10, -1, 3));
pointsLine1.push(new THREE.Vector3(25, -15, 3));
var geometryLine1 = new THREE.BufferGeometry().setFromPoints(pointsLine1);
var line1 = new THREE.Line(geometryLine1, new THREE.LineBasicMaterial({color: new THREE.Color("yellow")}))
scene.add(line1);

var pointsLine2= [];
pointsLine2.push(new THREE.Vector3(-20, 0, -2));
pointsLine2.push(new THREE.Vector3(-5, 3, -2));
pointsLine2.push(new THREE.Vector3(-1, 1, -2));
pointsLine2.push(new THREE.Vector3(10, -1, -2));
pointsLine2.push(new THREE.Vector3(25, -15, -2));
var geometryLine2 = new THREE.BufferGeometry().setFromPoints(pointsLine2);
var line1 = new THREE.Line(geometryLine2, new THREE.LineBasicMaterial({color: new THREE.Color("magenta")}))
scene.add(line1);

let planePolygon = new THREE.Plane();
planePolygon.setFromCoplanarPoints(pointsLine1[0], pointsLine1[1], pointsLine1[2]);

var coplanarPoint = new THREE.Vector3();
planePolygon.coplanarPoint(coplanarPoint);

const canvasTop = document.getElementById("top-camera");
const camaraTop = new THREE.PerspectiveCamera(50, 1, 0.1, 600);

camaraTop.position.z = -20;
camaraTop.position.y = 20;
camaraTop.position.x = 20;

//Top canvas
const rendererTop =...