LayaAir1.0 icon indicating copy to clipboard operation
LayaAir1.0 copied to clipboard

Laya.Stage.SCALE_SHOWALL模式下Ray射线不正确

Open watsonsong opened this issue 7 years ago • 0 comments

在使用Laya.stage.scaleMode = Laya.Stage.SCALE_SHOWALL;模式下的时候,通过Camera构造Ray的结果不正确。测试代码如下:

` import Camera = Laya.Camera; import PhasorSpriter3D = Laya.PhasorSpriter3D; import Ray = Laya.Ray; import RenderState = Laya.RenderState; import Script = Laya.Script; import Vector2 = Laya.Vector2; import Vector3 = Laya.Vector3; import Vector4 = Laya.Vector4; import WebGLContext = Laya.WebGLContext;

class SceneScript extends Script { private _originPosition: Vector3 = new Vector3(0, 0, 0); private _phasorSpriter3D: PhasorSpriter3D; private _color: Vector4 = new Vector4(1, 0, 0, 1); private _point: Vector2 = new Vector2(); private _camera: Camera; private _ray: Ray = new Ray(new Vector3(0, 0, 0), new Vector3(0, 0, 0));

public _start(state: RenderState): void {
    super._start(state);

    this._phasorSpriter3D = new PhasorSpriter3D();
    this._camera = this._owner.getChildByName("Camera") as Camera;
}

public _postRenderUpdate(state: RenderState): void {
    super._update(state);

    this._point.elements[0] = Laya.stage.mouseX;
    this._point.elements[1] = Laya.stage.mouseY;
    this._camera.viewportPointToRay(this._point, this._ray);

    this._phasorSpriter3D.begin(WebGLContext.LINES, this._camera);

    // 绘出射线
    this._phasorSpriter3D.line(
        this._ray.origin,
        this._color,
        this._originPosition,
        this._color);

    this._phasorSpriter3D.end();
}

}

// 程序入口 class GameMain { constructor() { Laya3D.init(1334, 768, true, true);

    Laya.stage.alignV = Laya.Stage.ALIGN_MIDDLE;
    Laya.stage.alignH = Laya.Stage.ALIGN_CENTER;

    Laya.stage.scaleMode = Laya.Stage.SCALE_SHOWALL;
    Laya.stage.bgColor = "#232628";

    Laya.Stat.show();

    let camera: Laya.Camera = new Laya.Camera();
    camera.name = "Camera";
    camera.transform.position = new Laya.Vector3(
        -6.87492561340332, 3.95000958442688, 1.06434166431427);
    camera.transform.rotation = new Laya.Quaternion(
        -0.19387270510196686,
        -0.6291995048522949,
        -0.16616787016391754,
        0.7341046333312988);
    let scene: Laya.Scene = new Laya.Scene();
    scene.addChild(camera);
    scene.addScript(SceneScript);
    Laya.stage.addChild(scene);
}

}

new GameMain(); `

watsonsong avatar Feb 02 '18 05:02 watsonsong