mirror of
https://gitee.com/ruanwujing/green-pack-cocos
synced 2025-10-09 16:46:17 +00:00
2渲3台球
This commit is contained in:
66
assets/scripts/testComponents/TestBilliards.ts
Normal file
66
assets/scripts/testComponents/TestBilliards.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { _decorator, Component, Mat4, Sprite, v3 } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
// dynamicAtlasManager.enabled = false;
|
||||
@ccclass('TestBilliards')
|
||||
export class TestBilliards extends Component {
|
||||
@property
|
||||
public scrollAxis = v3(1, 0, 0)
|
||||
|
||||
private matrix = new Mat4();
|
||||
private mat = [
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1]
|
||||
|
||||
@property
|
||||
public scrollSpeed = 0;
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
scroll(rad, x, y, z) {
|
||||
|
||||
// 矩阵旋转
|
||||
// 传入的是逆矩阵,所以计算反向旋转
|
||||
// 因为只需要计算3d旋转,所以用3x3矩阵表示
|
||||
const s = Math.sin(-rad);
|
||||
const c = Math.cos(-rad);
|
||||
const t = 1 - c;
|
||||
|
||||
|
||||
let a = this.mat;
|
||||
const a00 = a[0]; const a01 = a[1]; const a02 = a[2];
|
||||
const a10 = a[3]; const a11 = a[4]; const a12 = a[5];
|
||||
const a20 = a[6]; const a21 = a[7]; const a22 = a[8];
|
||||
|
||||
const b00 = x * x * t + c; const b01 = y * x * t + z * s; const b02 = z * x * t - y * s;
|
||||
const b10 = x * y * t - z * s; const b11 = y * y * t + c; const b12 = z * y * t + x * s;
|
||||
const b20 = x * z * t + y * s; const b21 = y * z * t - x * s; const b22 = z * z * t + c;
|
||||
|
||||
a[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
||||
a[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
||||
a[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
||||
|
||||
a[3] = a00 * b10 + a10 * b11 + a20 * b12;
|
||||
a[4] = a01 * b10 + a11 * b11 + a21 * b12;
|
||||
a[5] = a02 * b10 + a12 * b11 + a22 * b12;
|
||||
|
||||
a[6] = a00 * b20 + a10 * b21 + a20 * b22;
|
||||
a[7] = a01 * b20 + a11 * b21 + a21 * b22;
|
||||
a[8] = a02 * b20 + a12 * b21 + a22 * b22;
|
||||
|
||||
}
|
||||
update(dt) {
|
||||
let rad = dt * this.scrollSpeed;
|
||||
this.scroll(rad, this.scrollAxis.x, this.scrollAxis.y, this.scrollAxis.z);
|
||||
let a = this.mat
|
||||
this.matrix.set(
|
||||
a[0], a[1], a[2], 0,
|
||||
a[3], a[4], a[5], 0,
|
||||
a[6], a[7], a[8], 0,
|
||||
0, 0, 0, 0,)
|
||||
this.getComponent(Sprite).material.setProperty("b_matrix", this.matrix)
|
||||
}
|
||||
}
|
||||
|
||||
|
9
assets/scripts/testComponents/TestBilliards.ts.meta
Normal file
9
assets/scripts/testComponents/TestBilliards.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ca0bf6b0-a6ae-4cba-99fa-d512d0df98e0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
28
assets/scripts/testComponents/TestBilliardsParent.ts
Normal file
28
assets/scripts/testComponents/TestBilliardsParent.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { _decorator, Component, Node, v3 } from 'cc';
|
||||
import { TestBilliards } from './TestBilliards';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestBilliardsParent')
|
||||
export class TestBilliardsParent extends Component {
|
||||
start() {
|
||||
for (let i = 0; i < this.node.children.length; i++) {
|
||||
let ball:TestBilliards = this.node.children[i].getComponent(TestBilliards);
|
||||
|
||||
ball.scrollSpeed = (i + 1);
|
||||
|
||||
let ax = i % 4;
|
||||
let ay = Math.floor(i / 4);
|
||||
|
||||
let az = Math.sqrt(18 - ax * ax - ay * ay);
|
||||
let len = Math.sqrt(18);
|
||||
|
||||
ball.scrollAxis = v3(ax / len, ay / len, az / len);
|
||||
}
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f6003bdc-c4b1-4cd7-b2bf-27cac20ce0a0",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
33
assets/scripts/testComponents/TestPuzzle.ts
Normal file
33
assets/scripts/testComponents/TestPuzzle.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { _decorator, Component, instantiate, Node } from 'cc';
|
||||
import { PuzzleSprite } from '../puzzle/PuzzleSprite';
|
||||
const { ccclass, property, executeInEditMode} = _decorator;
|
||||
|
||||
@ccclass('TestPuzzle')
|
||||
@executeInEditMode(true)
|
||||
export class TestPuzzle extends Component {
|
||||
@property({type:Node})
|
||||
public piece:Node;
|
||||
start(): void {
|
||||
if (!this.piece)
|
||||
return
|
||||
|
||||
this.node.removeAllChildren();
|
||||
for (let c = 0; c < 10; c++) {
|
||||
for (let r = 0; r < 6; r++) {
|
||||
let idx = c + r * 10;
|
||||
if (idx < this.node.children.length)
|
||||
continue;
|
||||
let node = instantiate(this.piece);
|
||||
this.node.addChild(node)
|
||||
// let node = this.node.children[idx]
|
||||
node.setPosition(c * 80, (6 - r) * 80, 0)
|
||||
node.getComponent(PuzzleSprite).columnMax = 10
|
||||
node.getComponent(PuzzleSprite).rowMax = 6
|
||||
node.getComponent(PuzzleSprite).column = c + 1
|
||||
node.getComponent(PuzzleSprite).row = r + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
9
assets/scripts/testComponents/TestPuzzle.ts.meta
Normal file
9
assets/scripts/testComponents/TestPuzzle.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "001cf388-4bdf-4143-8ecf-bd9a2b618966",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user