3D working
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user