Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>CodePen - rotate points</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>
<!-- partial:index.partial.html -->
<canvas id="app"></canvas>

<!-- partial -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js'></script><script  src="./script.js"></script>

</body>
</html>
              
            
!

CSS

              
                #app {
  width: 100vw;
  height: 100vh;
}
              
            
!

JS

              
                
var go_half=0;
var go_left=0,go_right=0,go_up=0,go_down=0;
var player={};
player.position={x:0,y:1.5,z:2,s:0};
player.direction={x:0,y:0,z:-1};
player.angle={z:90,y:0};
var radian=Math.PI/180;


var mouse_sensitive=0.125;

var speed=0.1;
var go_lrc=Math.cos((player.angle.y)*radian)*speed;
var go_lrs=Math.sin((player.angle.y)*radian)*speed;
var go_udc=Math.cos((player.angle.y+90)*radian)*speed;
var go_uds=Math.sin((player.angle.y+90)*radian)*speed;


function lockChangeAlert(){
if(document.pointerLockElement===canvas || document.mozPointerLockElement===canvas){ document.addEventListener("mousemove",updatePosition,false); }
else{ document.removeEventListener("mousemove",updatePosition,false); }
}


function updatePosition(e,move_x,move_y){


// ÅÑËÈ ÍÅÒ move_x, ÇÍÀ×ÈÒ ÏÎÂÎÐÎÒ ÌÛØÊÎÉ
if(move_x==undefined){
player.angle.z+=e.movementY*mouse_sensitive;
player.angle.y-=e.movementX*mouse_sensitive;
}
// ÅÑËÈ ÅÑÒÜ, ÒÎ ÏÎÂÎÐÀ×ÈÂÀÅÌ ÍÀ ÝÒÓ ÂÅËÈ×ÈÍÓ
else{
player.angle.z-=move_y*mouse_sensitive;
player.angle.y+=move_x*mouse_sensitive;
}


if(player.angle.z>170){ player.angle.z=170; }
if(10>player.angle.z){ player.angle.z=10; }


if(player.angle.y>360){ player.angle.y-=360; }
if(player.angle.y<0){ player.angle.y+=360; }


go_lrc=Math.cos(player.angle.y*radian)*speed;
go_lrs=Math.sin(player.angle.y*radian)*speed;
go_udc=Math.cos((player.angle.y+90)*radian)*speed;
go_uds=Math.sin((player.angle.y+90)*radian)*speed;


player.direction.x=Math.cos((-player.angle.y-90)*radian)*(Math.sin(player.angle.z*radian));
player.direction.y=Math.cos(player.angle.z*radian);
player.direction.z=Math.sin((-player.angle.y-90)*radian)*(Math.sin(player.angle.z*radian));
try{
camera.lookAt(player.position.x+player.direction.x,player.position.y+player.direction.y,player.position.z+player.direction.z);
}
catch(e){}

}


function key(which,to){
if(which==65){ go_left=to; }
if(which==87){ go_up=to; }
if(which==68){ go_right=to; }
if(which==83){ go_down=to; }
}


document.onkeydown=function(e){ key((e||window.event).keyCode,1); }
document.onkeyup=function(e){ key((e||window.event).keyCode,0); }


var vs=[];
var fs=[];
var mesh=[];
var tex=[];
var mat=[];


var texture_loader=new THREE.TextureLoader();


const canvas=document.querySelector('#app');
const width=canvas.clientWidth;
const height=canvas.clientHeight;


canvas.requestPointerLock=canvas.requestPointerLock || canvas.mozRequestPointerLock;
document.exitPointerLock=document.exitPointerLock || document.mozExitPointerLock;
document.addEventListener("pointerlockchange",lockChangeAlert,false);
document.addEventListener("mozpointerlockchange",lockChangeAlert,false);
canvas.onclick=canvas.requestPointerLock;


const context=canvas.getContext('webgl');
const renderer=new THREE.WebGLRenderer({antialias:true,alpha:true,transparent:true,canvas:canvas,context:context});
renderer.setClearColor(0xB9EEFF,1);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(width, height, false);
renderer.shadowMap.enabled=false;
renderer.shadowMap.type=THREE.VSMShadowMap;


const camera=new THREE.PerspectiveCamera(45,width/height,0.05,100000);
const scene=new THREE.Scene();
const pl1=new THREE.PointLight(0xFEE3B1, 2);
pl1.position.set(-20,20,20);
scene.add(pl1);
const clock=new THREE.Clock();


tex["floor"]=texture_loader.load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAABGdBTUEAALGPC/xhBQAAADBQTFRFdH9HLjgQanY8Y280Xm0tW2YxOEMVVWEsT1soWGYoPUoZR1IgUmAjSVgdQ1AbTVsiMCbijgAAB/lJREFUSMcllXlMW/cBx3//TNo6Td3UHR1KyR9rm7Ppmq4hNAGkjRwQoNrSQIAAippAOIy1RpzmqJKAOY2Wg2B8KQ3BGF9KggHfSjA2Pp69BDAYP/u1AWPjZ7+nDvD1bL8lzd/fvz7SR98P+HN+b/CqKxzbaxEjIqfgETR04pTSNARDQVOCZ5yyAcuDCSvWMiHUh4OJ+5ordx0f+rF+po0Kp3LY3RriPSCeU0s+suiqanBHUp0VC0htn6F2us2bhFg4vFk8A+Tc9J4pmfbs9SLsCcGhIQ9JRlokk0VyjcQOzLtTADaI51m2nXb+/GZHuI9o109asL2xF24nW/yMmajLToIiGoOdNXwu1+Pd2Y/hqPb9G2zhA3Hdmov5PG/pb7dSgCfGtaQHZWKRVzVcZj3K+82OnbLRF7gcW6P0OrgZ7WCQSjPqlEcEXHNb0LmmEdegcbgykozmx8DhlyzYBFCzoWjRNsOUD5lqLPWVECU+aR1VwxBkGl/K11mSQJiussCljvt3i+ebNlV8ydWSbdmmajZEEWaLzpW/GAZsesmp9pg2SKjQsLZQ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VORK5CYII=");
tex["floor"].wrapS=tex["floor"].wrapT=THREE.RepeatWrapping;
tex["floor"].repeat.set(100,100);


mat["floor"]=new THREE.MeshStandardMaterial({
map:tex["floor"],bumpMap:tex["floor"],bumpScale:0.005,metalness:0.16
})


mesh["floor"]=new THREE.Mesh(new THREE.BoxBufferGeometry(100,1,100),mat["floor"]);
mesh["floor"].position.y=-0.5;
mesh["floor"].receiveShadow=true;
scene.add(mesh["floor"]);


mesh["sphere"]=new THREE.Mesh(new THREE.SphereBufferGeometry(0.2,16,16,16),new THREE.MeshPhongMaterial({color:0x009000}));
mesh["sphere"].position.y=2;
mesh["sphere"].castShadow=true;
scene.add(mesh["sphere"]);


var spotLight=new THREE.SpotLight(0xffffff,8);
spotLight.angle=Math.PI/10;
spotLight.penumbra=0.1;
spotLight.decay=2;
spotLight.distance=20;

spotLight.castShadow=true;
spotLight.shadow.mapSize.width=512;
spotLight.shadow.mapSize.height=512;
spotLight.shadow.camera.near=10;
spotLight.shadow.camera.far=200;
spotLight.shadow.focus=1;
scene.add(spotLight);


var spotLightTarget=new THREE.Object3D();
scene.add(spotLightTarget);
spotLight.target=mesh["sphere"];


var lightHelper=new THREE.SpotLightHelper(spotLight);
scene.add(lightHelper);


const pLight=new THREE.PointLight(0xffff00,1);
scene.add(pLight);


var item_1=mesh["sphere"].position;
var item_2=camera.position;


function loop(){


requestAnimationFrame(loop);


go_half=0;


if(go_left==1){ go_half++; }
if(go_right==1){ go_half++; ; }
if(go_up==1){ go_half++; }
if(go_down==1){ go_half++; }


if(go_half>1){ go_half=0.68; }


if(go_left==1){ player.position.x-=go_lrc*go_half; player.position.z+=go_lrs*go_half; }
if(go_right==1){ player.position.x+=go_lrc*go_half; player.position.z-=go_lrs*go_half; }
if(go_up==1){ player.position.x+=go_udc*go_half; player.position.z-=go_uds*go_half; }
if(go_down==1){ player.position.x-=go_udc*go_half; player.position.z+=go_uds*go_half; }


camera.position.set(player.position.x,player.position.y,player.position.z);


var x=item_1.x-item_2.x;
var y=item_1.y-item_2.y;
var z=item_1.z-item_2.z;
var divide=1/Math.sqrt(x*x+y*y+z*z);
x*=divide;
y*=divide;
z*=divide;


var distance=5;
x*=distance;
y*=distance;
z*=distance;


spotLight.position.set(item_1.x+x,item_1.y+y,item_1.z+z);
pLight.position.set(item_1.x+x,item_1.y+y,item_1.z+z);


lightHelper.update();


renderer.render(scene,camera);


}


loop();
              
            
!
999px

Console