3D working

This commit is contained in:
Kbz-8
2024-02-22 06:01:56 +01:00
parent 81355bf7b5
commit a7fff2f1a2
13 changed files with 71 additions and 50 deletions

View File

@ -7,13 +7,15 @@ class Segment
* @param {Point} start
* @param {Point} stop
*/
constructor(start, stop)
constructor(game, start, stop)
{
/**
* @type {Point}
*/
this.start = start === undefined ? new Point() : start;
this.game = game;
/**
* @type {Point}
*/
@ -37,11 +39,8 @@ class Segment
return (x ** 2 + y ** 2) ** (1 / 2);
}
/**
* @param {CanvasRenderingContext2D} ctx
*/
draw(ctx)
{
draw(ctx)
{
if(ctx instanceof CanvasRenderingContext2D)
{
ctx.moveTo(this.start.x, this.start.y);
@ -49,19 +48,23 @@ class Segment
}
else if(ctx instanceof WebGLRenderingContext)
{
renderCube(ctx, this.start.x, -3, this.start.y, 0, 0.5, 0.5, 0.5);
const size = this.game.config.ball_size * 2;
const sizex = this.len() / 2;
const posx = (this.start.x - this.game.config.center_x);
const posy = (this.start.y - this.game.config.center_y);
renderCube(ctx, posx, 0, posy, -this.angle(), sizex, size, size);
}
else
{
alert('Unknown rendering context type');
}
}
}
from_json(data)
{
this.start = this.start.from_json(data.start);
this.stop = this.stop.from_json(data.stop);
return this;
}
}