it编程 > 网页制作 > 网页播放器

html3D创意相册附源码_html相册源码(2)

370人参与 2024-08-06 网页播放器

			math.round(c.g \* s) + "," + 
			math.round(c.b \* s) + "," + (c.a || 1) + ")";
		ctx.fillstyle = light;
	}
	// ---- paint poly ----
	if (!c.light || this.parent.light < 1) {
		// ---- projection ----
		for (
			var i = 0; 
			this.points[i++].projection();
		);
		this.drawpoly();
		ctx.fill();
	}
}
/\* ==== image onload ==== \*/
diapo.prototype.loaded = function (img) {
	// ---- create points ----
	var d = [-1,1,1,-1,1,1,-1,-1];
	var w = img.texture.width  \* 0.5;
	var h = img.texture.height \* 0.5;
	for (var i = 0; i < 4; i++) {
		img.points[i] = new ge1doot.transform3d.point(
			this.pc.x + (w \* this.normalz \* d[i]),
			this.pc.y + (h \* d[i + 4]),
			this.pc.z + (w \* this.normalx \* d[i])
		);
	}
}
/\* ==== images draw ==== \*/
diapo.prototype.draw = function () {
	// ---- visibility ----
	this.pc.projection();
	if (this.pc.z > -(camera.focallength >> 1) && this.img.transform3d(true)) {
		// ---- light ----
		this.light = 0.5 + math.abs(this.normalz \* camera.cosy - this.normalx \* camera.siny) \* 0.6;
		// ---- draw image ----
		this.visible = true;
		this.img.draw();
		// ---- test pointer inside ----
		if (pointer.hasmoved || pointer.isdown) {
			if (
				this.img.ispointerinside(
					pointer.x,
					pointer.y
				)
			) camera.over = this;
		}
	} else this.visible = false;
	return true;
}
return {
	// --- load data ----
	load : function (data) {
		window.addeventlistener('load', function () {
			ge1doot.loadjs(
				"js/imagetransform3d.js",
				init, data
			);
		}, false);
	}
}

})().load({
imgdata:[
// north
{img:‘imgs/1.jpg’, x:-1000, y:0, z:1500, nx:0, nz:1},
{img:‘imgs/2.jpg’, x:0, y:0, z:1500, nx:0, nz:1},
{img:‘imgs/3.jpg’, x:1000, y:0, z:1500, nx:0, nz:1},
// east
{img:‘imgs/4.jpg’, x:1500, y:0, z:1000, nx:-1, nz:0},
{img:‘imgs/5.jpg’, x:1500, y:0, z:0, nx:-1, nz:0},
{img:‘imgs/6.jpg’, x:1500, y:0, z:-1000, nx:-1, nz:0},
// south
{img:‘imgs/7.jpg’, x:1000, y:0, z:-1500, nx:0, nz:-1},
{img:‘imgs/8.jpg’, x:0, y:0, z:-1500, nx:0, nz:-1},
{img:‘imgs/9.jpg’, x:-1000, y:0, z:-1500, nx:0, nz:-1},
// west
{img:‘imgs/10.jpg’, x:-1500, y:0, z:-1000, nx:1, nz:0},
{img:‘imgs/11.jpg’, x:-1500, y:0, z:0, nx:1, nz:0},
{img:‘imgs/12.jpg’, x:-1500, y:0, z:1000, nx:1, nz:0}
],
structure:[
{
// wall
fill: {r:255, g:255, b:255, light:1},
x: [-1001,-490,-490,-1001],
z: [-500,-500,-500,-500],
y: [500,500,-500,-500]
},{
// wall
fill: {r:255, g:255, b:255, light:1},
x: [-501,2,2,-500],
z: [-500,-500,-500,-500],
y: [500,500,-500,-500]
},{
// wall
fill: {r:255, g:255, b:255, light:1},
x: [0,502,502,0],
z: [-500,-500,-500,-500],
y: [500,500,-500,-500]
},{
// wall
fill: {r:255, g:255, b:255, light:1},
x: [490,1002,1002,490],
z: [-500,-500,-500,-500],
y: [500,500,-500,-500]
},{
// shadow
fill: {r:0, g:0, b:0, a:0.2},
x: [-420,420,420,-420],
z: [-500,-500,-500,-500],
y: [150, 150,-320,-320]
},{
// shadow
fill: {r:0, g:0, b:0, a:0.2},
x: [-20,20,20,-20],
z: [-500,-500,-500,-500],
y: [250, 250,150,150]
},{
// shadow
fill: {r:0, g:0, b:0, a:0.2},
x: [-20,20,20,-20],
z: [-500,-500,-500,-500],
y: [-320, -320,-500,-500]
},{
// shadow
fill: {r:0, g:0, b:0, a:0.2},
x: [-20,20,10,-10],
z: [-500,-500,-100,-100],
y: [-500, -500,-500,-500]
},{
// base
fill: {r:32, g:32, b:32},
x: [-50,50,50,-50],
z: [-150,-150,-50,-50],
y: [-500,-500,-500,-500]
},{
// support
fill: {r:16, g:16, b:16},
x: [-10,10,10,-10],
z: [-100,-100,-100,-100],
y: [300,300,-500,-500]
},{
// frame
fill: {r:255, g:255, b:255},
x: [-320,-320,-320,-320],
z: [0,-20,-20,0],
y: [-190,-190,190,190]
},{
// frame
fill: {r:255, g:255, b:255},
x: [320,320,320,320],
z: [0,-20,-20,0],
y: [-190,-190,190,190]
},
{img:true},
{
// ceilinglight
fill: {r:255, g:128, b:0},
x: [-50,50,50,-50],
z: [450,450,550,550],
y: [500,500,500,500]
},{
// groundlight
fill: {r:255, g:128, b:0},
x: [-50,50,50,-50],
z: [450,450,550,550],
y: [-500,-500,-500,-500]
}
],
options:{
imagespath: “”
}
});

你的浏览器不支持html5画布技术,请使用谷歌浏览器。


js文件目录:  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/1d4b44f1fee044368a334e7e669d192c.png)  
 **ge1doot.js**



var ge1doot = ge1doot || {
json: null,
screen: null,
pointer: null,
camera: null,
loadjs: function (url, callback, data) {
if (typeof url == “string”) url = [url];
var load = function (src) {
var script = document.createelement(“script”);
if (callback) {
if (script.readystate){
script.onreadystatechange = function () {
if (script.readystate == “loaded” || script.readystate == “complete”){
script.onreadystatechange = null;
if (–n === 0) callback(data || false);
}
}
} else {
script.onload = function() {
if (–n === 0) callback(data || false);
}
}
}
script.src = src;
document.getelementsbytagname(“head”)[0].appendchild(script);
}
for (var i = 0, n = url.length; i < n; i++) load(url[i]);
}
}

// ===== html/canvas container =====

ge1doot.screen = function (setup) {
ge1doot.screen = this;
this.elem = document.getelementbyid(setup.container) || setup.container;
this.ctx = this.elem.tagname == “canvas” ? this.elem.getcontext(“2d”) : false;
this.style = this.elem.style;
this.left = 0;
this.top = 0;
this.width = 0;
this.height = 0;
this.cursor = “default”;
this.setup = setup;
this.resize = function () {
var o = this.elem;
this.width = o.offsetwidth;
this.height = o.offsetheight;
for (this.left = 0, this.top = 0; o != null; o = o.offsetparent) {
this.left += o.offsetleft;
this.top += o.offsettop;
}
if (this.ctx) {
this.elem.width = this.width;
this.elem.height = this.height;
}
this.setup.resize && this.setup.resize();
}
this.setcursor = function (type) {
if (type !== this.cursor && ‘ontouchstart’ in window === false) {
this.cursor = type;
this.style.cursor = type;
}
}
window.addeventlistener(‘resize’, function () {
ge1doot.screen.resize();
}, false);
!this.setup.resize && this.resize();
}

// ==== unified touch events handler ====

ge1doot.pointer = function (setup) {
ge1doot.pointer = this;
var self = this;
var body = document.body;
var html = document.documentelement;
this.setup = setup;
this.screen = ge1doot.screen;
this.elem = this.screen.elem;
this.x = 0;
this.y = 0;
this.xi = 0;
this.yi = 0;
this.bxi = 0;
this.byi = 0;
this.xr = 0;
this.yr = 0;
this.startx = 0;
this.starty = 0;
this.scale = 0;
this.wheeldelta = 0;
this.isdraging = false;
this.hasmoved = false;
this.isdown = false;
this.evt = false;
var sx = 0;
var sy = 0;
// prevent default behavior
if (setup.tap) this.elem.onclick = function () { return false; }
if (!setup.documentmove) {
document.ontouchmove = function(e) { e.preventdefault(); }
}
document.addeventlistener(“msholdvisual”, function(e) { e.preventdefault(); }, false);
if (typeof this.elem.style.mstouchaction != ‘undefined’) this.elem.style.mstouchaction = “none”;

this.pointerdown = function (e) {
	if (!this.isdown) {
		if (this.elem.setcapture) this.elem.setcapture();
		this.isdraging = false;
		this.hasmoved = false;
		this.isdown = true;
		this.evt = e;
		this.xr = (e.clientx !== undefined ? e.clientx : e.touches[0].clientx);
		this.yr = (e.clienty !== undefined ? e.clienty : e.touches[0].clienty);
		this.x  = sx = this.xr - this.screen.left;
		this.y  = sy = this.yr - this.screen.top + ((html && html.scrolltop) || body.scrolltop);
		this.setup.down && this.setup.down(e);
	}
}
this.pointermove = function(e) {
	this.xr = (e.clientx !== undefined ? e.clientx : e.touches[0].clientx);
	this.yr = (e.clienty !== undefined ? e.clienty : e.touches[0].clienty);
	this.x  = this.xr - this.screen.left;
	this.y  = this.yr - this.screen.top + ((html && html.scrolltop) || body.scrolltop);
	if (this.isdown) {
		this.xi = this.bxi + (this.x - sx);
		this.yi = this.byi - (this.y - sy);
	}
	if (math.abs(this.x - sx) > 11 || math.abs(this.y - sy) > 11) {
		this.hasmoved = true;
		if (this.isdown) {
			if (!this.isdraging) {
				this.startx = sx;
				this.starty = sy;
				this.setup.startdrag && this.setup.startdrag(e);
				this.isdraging = true;
			} else {
				this.setup.drag && this.setup.drag(e);
			}
		} else {
			sx = this.x;
			sy = this.y;
		}
	}
	this.setup.move && this.setup.move(e);
}
this.pointerup = function(e) {
	this.bxi = this.xi;
	this.byi = this.yi;
	if (!this.hasmoved) {
		this.x = sx;
		this.y = sy;
		this.setup.tap && this.setup.tap(this.evt);
	} else {
		this.setup.up && this.setup.up(this.evt);
	}
	this.isdraging = false;
	this.isdown = false;
	this.hasmoved = false;
	this.setup.up && this.setup.up(this.evt);
	if (this.elem.releasecapture) this.elem.releasecapture();
	this.evt = false;
}
this.pointercancel = function(e) {
	if (this.elem.releasecapture) this.elem.releasecapture();
	this.isdraging = false;
	this.hasmoved = false;
	this.isdown = false;
	this.bxi = this.xi;
	this.byi = this.yi;
	sx = 0;
	sy = 0;
}
if ('ontouchstart' in window) {
	this.elem.ontouchstart      = function (e) { self.pointerdown(e); return false;  }
	this.elem.ontouchmove       = function (e) { self.pointermove(e); return false;  }
	this.elem.ontouchend        = function (e) { self.pointerup(e); return false;    }
	this.elem.ontouchcancel     = function (e) { self.pointercancel(e); return false;}
}
document.addeventlistener("mousedown", function (e) {
	if (
		e.target === self.elem || 
		(e.target.parentnode && e.target.parentnode === self.elem) || 
		(e.target.parentnode.parentnode && e.target.parentnode.parentnode === self.elem)
	) {
		if (typeof e.stoppropagation != "undefined") {
			e.stoppropagation();
		} else {
			e.cancelbubble = true;
		}
		e.preventdefault();
		self.pointerdown(e); 
	}
}, false);
document.addeventlistener("mousemove", function (e) { self.pointermove(e); }, false);
document.addeventlistener("mouseup",   function (e) {
	self.pointerup(e);
}, false);
document.addeventlistener('gesturechange', function(e) {
	e.preventdefault();
	if (e.scale > 1) self.scale = 0.1; else if (e.scale < 1) self.scale = -0.1; else self.scale = 0;
	self.setup.scale && self.setup.scale(e);
	return false;
}, false);
if (window.navigator.mspointerenabled) {
	var ncontact = 0;
	var mygesture = new msgesture();
	mygesture.target = this.elem;
	this.elem.addeventlistener("mspointerdown", function(e) {
		if (e.pointertype == e.mspointer_type_touch) {
			mygesture.addpointer(e.pointerid);
			ncontact++;
		}
	}, false);
	this.elem.addeventlistener("mspointerout", function(e) {
		if (e.pointertype == e.mspointer_type_touch) {
			ncontact--;
		}
	}, false);
	this.elem.addeventlistener("msgesturehold", function(e) {
		e.preventdefault();
	}, false);
	this.elem.addeventlistener("msgesturechange", function(e) {
		if (ncontact > 1) {
			if (e.preventdefault) e.preventdefault(); 
			self.scale = e.velocityexpansion;
			self.setup.scale && self.setup.scale(e);
		}
		return false;
	}, false);
}
if (window.addeventlistener) this.elem.addeventlistener('dommousescroll', function(e) { 
	if (e.preventdefault) e.preventdefault(); 
	self.wheeldelta = e.detail \* 10;
	self.setup.wheel && self.setup.wheel(e);
	return false; 
}, false); 
this.elem.onmousewheel = function () { 
	self.wheeldelta = -event.wheeldelta \* .25;
	self.setup.wheel && self.setup.wheel(event);
	return false; 
}

}
// ===== request animation frame =====

window.requestanimframe = (function(){
return window.requestanimationframe ||
window.webkitrequestanimationframe ||
window.mozrequestanimationframe ||
window.orequestanimationframe ||
window.msrequestanimationframe ||
function( run ){
window.settimeout(run, 16);
};
})();


**imagetransform3d.js**



“use strict”;

var ge1doot = ge1doot || {};
ge1doot.transform3d = {};

/* ==== draw poly ==== */
ge1doot.transform3d.drawpoly = function () {
this.ctx.beginpath();
this.ctx.moveto(this.points[0].x, this.points[0].y);
this.ctx.lineto(this.points[1].x, this.points[1].y);
this.ctx.lineto(this.points[2].x, this.points[2].y);
this.ctx.lineto(this.points[3].x, this.points[3].y);
this.ctx.closepath();
}
/* =============== camera constructor ================= */
ge1doot.transform3d.camera = function (setup, func) {
ge1doot.camera = this;
this.x = 0;
this.y = 0;
this.z = 0;
this.rx = 0;
this.ry = 0;
this.rz = 0;
this.focallength = setup.focallength || 500;
this.easetranslation = setup.easetranslation || 0.1;
this.easerotation = setup.easerotation || 0.025;
this.enablerx = setup.disablerx ? false : true;
this.enablery = setup.disablery ? false : true;
this.enablerz = setup.disablerz ? false : true;
this.cmov = false;
this.cosx = 1;
this.sinx = 0;
this.cosy = 1;
this.siny = 0;
this.cosz = 1;
this.sinz = 0;
this.target = {
over: false,
elem: false,
x: 0,
y: 0,
z: 0,
rx: 0,
ry: 0,
rz: 0
};
// ---- def custom move ----
if (func && func.move) this.cmov = func.move;
}
/* ==== easing ==== */
ge1doot.transform3d.camera.prototype.ease = function (target, value) {
while (math.abs(target - value) > math.pi) {
if (target < value) value -= 2 * math.pi;
else value += 2 * math.pi;
}
return (target - value) * this.easerotation;
}
/* ==== move / rotate camera ==== */
ge1doot.transform3d.camera.prototype.move = function () {
// ---- run custom function ----
this.cmov && this.cmov();
// ---- translations ----
this.x += (this.target.x - this.x) * this.easetranslation;
this.y += (this.target.y - this.y) * this.easetranslation;
this.z += (this.target.z - this.z) * this.easetranslation;
// ---- rotation rx ----
if (this.enablerx) {
this.rx += this.ease(this.target.rx, this.rx);
this.cosx = math.cos(this.rx);
this.sinx = math.sin(this.rx);
}
// ---- rotation ry ----
if (this.enablery) {
this.ry += this.ease(this.target.ry, this.ry);
this.cosy = math.cos(this.ry);
this.siny = math.sin(this.ry);
}
// ---- rotation rz ----
if (this.enablerz) {
this.rz += this.ease(this.target.rz, this.rz);
this.cosz = math.cos(this.rz);
this.sinz = math.sin(this.rz);
}
}
/* =============== point constructor ================= */
ge1doot.transform3d.point = function (x, y, z, tx, ty) {
this.x = x;
this.y = y;
this.z = z;
this.tx = tx || 0;
this.ty = ty || 0;
this.visible = false;
this.scale = 0;
this.x = 0;
this.y = 0;
this.z = 0;
this.next = true;
}
/* ==== perspective projection ==== */
ge1doot.transform3d.point.prototype.projection = function () {
var sw = this.scr.width >> 1;
var sh = this.scr.height >> 1;
// ---- 3d coordinates ----
var nx = this.x - this.camera.x;
var ny = this.y - this.camera.y;
var nz = this.z - this.camera.z;
// ---- 3d rotation and projection ----
if (this.camera.enablerz) {
var u = this.camera.sinz * ny + this.camera.cosz * nx;
var t = this.camera.cosz * ny - this.camera.sinz * nx;
} else {
var u = nx;
var t = ny;
}
var s = this.camera.cosy * nz + this.camera.siny * u;
this.z = this.camera.cosx * s - this.camera.sinx * t;
this.scale = this.camera.focallength / math.max(1, this.z);
this.x = sw + (this.camera.cosy * u - this.camera.siny * nz) * this.scale;
this.y = -(this.camera.y >> 1) + sh - (this.camera.sinx * s + this.camera.cosx * t) * this.scale;
// ---- visibility test ----
this.visible = (
this.x > -sw * 0.5 && this.x < sw * 2.5
) && (
this.y > -sh * 0.5 && this.y < sh * 2.5
);
// ----return next (fast loop) ----
return this.next;
}
/* ==== triangle constructor ==== */
ge1doot.transform3d.triangle = function (parent, p0, p1, p2) {
this.ctx = parent.ctx;
this.texture = parent.texture;
this.p0 = p0;
this.p1 = p1;
this.p2 = p2;
this.d = p0.tx * (p2.ty - p1.ty) - p1.tx * p2.ty + p2.tx * p1.ty + (p1.tx - p2.tx) * p0.ty;
this.pmy = p1.ty - p2.ty;
this.pmx = p1.tx - p2.tx;
this.pxy = p2.tx * p1.ty - p1.tx * p2.ty;

结尾

正式学习前端大概 3 年多了,很早就想整理这个书单了,因为常常会有朋友问,前端该如何学习,学习前端该看哪些书,我就讲讲我学习的道路中看的一些书,虽然整理的书不多,但是每一本都是那种看一本就秒不绝口的感觉。

以下大部分是我看过的,或者说身边的人推荐的书籍,每一本我都有些相关的推荐语,如果你有看到更好的书欢迎推荐呀。

gle = function (parent, p0, p1, p2) {
this.ctx = parent.ctx;
this.texture = parent.texture;
this.p0 = p0;
this.p1 = p1;
this.p2 = p2;
this.d = p0.tx * (p2.ty - p1.ty) - p1.tx * p2.ty + p2.tx * p1.ty + (p1.tx - p2.tx) * p0.ty;
this.pmy = p1.ty - p2.ty;
this.pmx = p1.tx - p2.tx;
this.pxy = p2.tx * p1.ty - p1.tx * p2.ty;

结尾

正式学习前端大概 3 年多了,很早就想整理这个书单了,因为常常会有朋友问,前端该如何学习,学习前端该看哪些书,我就讲讲我学习的道路中看的一些书,虽然整理的书不多,但是每一本都是那种看一本就秒不绝口的感觉。

以下大部分是我看过的,或者说身边的人推荐的书籍,每一本我都有些相关的推荐语,如果你有看到更好的书欢迎推荐呀。

前端学习书籍导图-1

(0)
打赏 微信扫一扫 微信扫一扫

您想发表意见!!点此发布评论

推荐阅读

使用Cesium加载和调整本地数据的3D Tiles点云

08-06

8 种网络协议

08-06

Selenium实现滑动滑块验证码验证

08-06

jmeter性能优化之tomcat配置与基础调优

08-06

阿里面试官:说一下RecyclerView-性能优化(1)

08-06

U盘启动盘 制作Linux Ubuntu CentOS系统启动盘 系统安装

08-06

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论