math_3d.h头文件源码

转自gitHub

#pragma once
#ifndef MATH_3D_H
#define	MATH_3D_H

#include <stdio.h>
#include <math.h>

#define ToRadian(x) ((x) * M_PI / 180.0f)
#define ToDegree(x) ((x) * 180.0f / M_PI)

struct Vector2i
{
	int x;
	int y;
};

struct Vector2f
{
	float x;
	float y;

	Vector2f()
	{
	}

	Vector2f(float _x, float _y)
	{
		x = _x;
		y = _y;
	}
};


struct Vector3f
{
	float x;
	float y;
	float z;

	Vector3f()
	{
	}

	Vector3f(float _x, float _y, float _z)
	{
		x = _x;
		y = _y;
		z = _z;
	}

	Vector3f& operator+=(const Vector3f& r)
	{
		x += r.x;
		y += r.y;
		z += r.z;

		return *this;
	}

	Vector3f& operator-=(const Vector3f& r)
	{
		x -= r.x;
		y -= r.y;
		z -= r.z;

		return *this;
	}

	Vector3f& operator*=(float f)
	{
		x *= f;
		y *= f;
		z *= f;

		return *this;
	}

	Vector3f Cross(const Vector3f& v) const;

	Vector3f& Normalize();

	void Rotate(float Angle, const Vector3f& Axis);

	void Print() const
	{
		printf("(%.02f, %.02f, %.02f", x, y, z);
	}
};


inline Vector3f operator+(const Vector3f& l, const Vector3f& r)
{
	Vector3f Ret(l.x + r.x,
		l.y + r.y,
		l.z + r.z);

	return Ret;
}

inline Vector3f operator-(const Vector3f& l, const Vector3f& r)
{
	Vector3f Ret(l.x - r.x,
		l.y - r.y,
		l.z - r.z);

	return Ret;
}

inline Vector3f operator*(const Vector3f& l, float f)
{
	Vector3f Ret(l.x * f,
		l.y * f,
		l.z * f);

	return Ret;
}


class Matrix4f
{
public:
	float m[4][4];

	Matrix4f()
	{
	}


	inline void InitIdentity()
	{
		m[0][0] = 1.0f; m[0][1] = 0.0f; m[0][2] = 0.0f; m[0][3] = 0.0f;
		m[1][0] = 0.0f; m[1][1] = 1.0f; m[1][2] = 0.0f; m[1][3] = 0.0f;
		m[2][0] = 0.0f; m[2][1] = 0.0f; m[2][2] = 1.0f; m[2][3] = 0.0f;
		m[3][0] = 0.0f; m[3][1] = 0.0f; m[3][2] = 0.0f; m[3][3] = 1.0f;
	}

	inline Matrix4f operator*(const Matrix4f& Right) const
	{
		Matrix4f Ret;

		for (unsigned int i = 0; i < 4; i++) {
			for (unsigned int j = 0; j < 4; j++) {
				Ret.m[i][j] = m[i][0] * Right.m[0][j] +
					m[i][1] * Right.m[1][j] +
					m[i][2] * Right.m[2][j] +
					m[i][3] * Right.m[3][j];
			}
		}

		return Ret;
	}

	void InitScaleTransform(float ScaleX, float ScaleY, float ScaleZ);
	void InitRotateTransform(float RotateX, float RotateY, float RotateZ);
	void InitTranslationTransform(float x, float y, float z);
	void InitCameraTransform(const Vector3f& Target, const Vector3f& Up);
	void InitPersProjTransform(float FOV, float Width, float Height, float zNear, float zFar);
};


struct Quaternion
{
	float x, y, z, w;

	Quaternion(float _x, float _y, float _z, float _w);

	void Normalize();

	Quaternion Conjugate();
};

Quaternion operator*(const Quaternion& l, const Quaternion& r);

Quaternion operator*(const Quaternion& q, const Vector3f& v);

#endif	/* MATH_3D_H */
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【视频教程】Hands-on Three.js 3D Web Visualisations-September 16, 2019.part2.rar Hands-on Three.js 3D Web Visualisations September 16, 2019 English | MP4 | AVC 1920×1080 | AAC 48KHz 2ch | 3h 46m | 968 MB eLearning | Skill level: All Levels Create stunning visualizations and 3D scenes using the Three.js library Three.js is the most popular JavaScript library for displaying 3D content on the web, giving you the power to display incredible models, games, music videos, and scientific/data visualizations in your browser and even on your smartphone! This course begins with a 3D beginner-level primer to 3D concepts and some basic examples to get you started with the most important features that Three.js has to offer. You’ll learn how to quickly create a scene, camera, and renderer and how to add meshes using the Geometry primitives included with the library. You’ll explore troubleshooting steps that will focus on some of the common pitfalls developers face. You’ll learn the very sophisticated animation system included with the library. The course concludes by introducing post-processing, essentially adding filters to your rendered scene, and GLSL, the shading language that is used by all materials included with the library. You’ll see how creating your materials is easier than you’d imagine using GLSL. By the end of this course, you’ll be able to quickly add advanced features to your 3D scenes, improve the way users interact with them, and make them look stunning. Learn Learn the basics of 3D applications: vertices, faces, meshes, cameras, and renderers Learn how to set up a Three.js web app: the scene, camera, and renderer Master the scene hierarchy and child-parent relationships, and how they affect the final location and orientation of objects Explore simple mesh shapes (such as boxes, spheres, cylinders, planes, and cones) using the Three.js library Learn how to source, create, and load complex assets, including textures Discover how to use the brilliant animation system that is part of the THREE.js library Add a post-processor to a rendered image, to make it look like an old film or a dot screenprint + Table of Contents 1 The Course Overview 2 Introducing the THREE.js website 3 D Basics 4 Your first THREE.js web page` 5 The THREE.js Editor 6 Debugging Your Pages 7 Let’s Keep It Simple – Starting with a Box 8 Materials One – Basic and Wireframe 9 Spheres and Cylinders 10 Materials Two – Lambert and Phong 11 Cones and Tori 12 Scene Hierarchy 13 Perspective Camera 14 Orthographic Camera 15 Dummy Cameras and Lerping 16 Complex Camera Paths 17 Ambient and Hemisphere Lighting 18 Directional and Point Lighting 19 Spot and RectArea Lighting 20 Adding Shadows to Your Scenes 21 Physically Correct Lighting 22 Online Sources of 3D Assets 23 Using Blender with THREE.js 24 The GLTFLoader Class 25 The FBXLoader Class 26 LatheGeometry and ExtrudeGeometry 27 The Basics of the Animation System 28 Skinned Meshes 29 Switching and Blending Animations 30 Splitting an Animation Clip 31 A WASD Control System for a Player Character 32 THREE.js Post Processing 33 Introducing GLSL – ShaderMaterial 34 Introducing GLSL – Vertex Shaders 35 Introducing GLSL – Importance of Noise Function 36 Introducing GLSL – Textures

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值