aboutsummaryrefslogtreecommitdiff
path: root/NvCloth/samples/SampleBase/renderer/RenderUtils.h
blob: f4d007bb1e5f47f54ebc3a9100db93538d2eade4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (c) 2008-2017, NVIDIA CORPORATION.  All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto.  Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/

#ifndef RENDER_UTILS_H
#define RENDER_UTILS_H

#include "DirectXTex.h"
#include <DirectXMath.h>
#include "PxMat44.h"
#include "PxVec3.h"
#include "PxVec4.h"

static DirectX::XMFLOAT4 getRandomPastelColor()
{
	float r = ((double)rand() / (RAND_MAX)) * 0.5f + 0.5f;
	float g = ((double)rand() / (RAND_MAX)) * 0.5f + 0.5f;
	float b = ((double)rand() / (RAND_MAX)) * 0.5f + 0.5f;
	return DirectX::XMFLOAT4(r, g, b, 1.0f);
}

static physx::PxMat44 XMMATRIXToPxMat44(const DirectX::XMMATRIX& mat)
{
	physx::PxMat44 m;
	memcpy(const_cast<float*>(m.front()), &mat.r[0], 4 * 4 * sizeof(float));
	return m;
}

static DirectX::XMMATRIX PxMat44ToXMMATRIX(const physx::PxMat44& mat)
{
	return DirectX::XMMATRIX(mat.front());
}

static physx::PxVec4 XMVECTORToPxVec4(const DirectX::XMVECTOR& vec)
{
	DirectX::XMFLOAT4 f;
	DirectX::XMStoreFloat4(&f, vec);
	return physx::PxVec4(f.x, f.y, f.z, f.w);
}

static physx::PxVec3 XMFLOAT3ToPxVec3(const DirectX::XMFLOAT3& vec)
{
	return physx::PxVec3(vec.x, vec.y, vec.z);
}

static physx::PxVec4 XMFLOAT4ToPxVec4(const DirectX::XMFLOAT4& vec)
{
	return physx::PxVec4(vec.x, vec.y, vec.z, vec.w);
}

static uint32_t XMFLOAT4ToU32Color(const DirectX::XMFLOAT4& color)
{
	uint32_t c = 0;
	c |= (int)(color.w * 255); c <<= 8;
	c |= (int)(color.z * 255); c <<= 8;
	c |= (int)(color.y * 255); c <<= 8;
	c |= (int)(color.x * 255);
	return c;
}

static DirectX::XMFLOAT4 XMFLOAT4Lerp(const DirectX::XMFLOAT4 v0, const DirectX::XMFLOAT4 v1, float val)
{
	DirectX::XMFLOAT4 v(
		v0.x * (1 - val) + v1.x * val,
		v0.y * (1 - val) + v1.y * val,
		v0.z * (1 - val) + v1.z * val,
		v0.w * (1 - val) + v1.w * val
		);
	return v;
}

#endif //RENDER_UTILS_H