ReactOS 0.4.15-dev-5667-ged97270
d3dx9shape.h File Reference
#include "d3dx9.h"
Include dependency graph for d3dx9shape.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define D3DXCreateText   WINELIB_NAME_AW(D3DXCreateText)
 

Functions

HRESULT WINAPI D3DXCreateBox (struct IDirect3DDevice9 *device, float width, float height, float depth, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreateCylinder (struct IDirect3DDevice9 *device, float radius1, float radius2, float length, UINT slices, UINT stacks, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreatePolygon (struct IDirect3DDevice9 *device, float length, UINT sides, struct ID3DXMesh **mesh, ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreateSphere (struct IDirect3DDevice9 *device, float radius, UINT slices, UINT stacks, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreateTeapot (struct IDirect3DDevice9 *device, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
 
HRESULT WINAPI D3DXCreateTextA (struct IDirect3DDevice9 *device, HDC hdc, const char *text, float deviation, float extrusion, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency, GLYPHMETRICSFLOAT *glyphmetrics)
 
HRESULT WINAPI D3DXCreateTextW (struct IDirect3DDevice9 *device, HDC hdc, const WCHAR *text, float deviation, FLOAT extrusion, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency, GLYPHMETRICSFLOAT *glyphmetrics)
 
HRESULT WINAPI D3DXCreateTorus (struct IDirect3DDevice9 *device, float innerradius, float outerradius, UINT sides, UINT rings, struct ID3DXMesh **mesh, ID3DXBuffer **adjacency)
 

Macro Definition Documentation

◆ D3DXCreateText

#define D3DXCreateText   WINELIB_NAME_AW(D3DXCreateText)

Definition at line 44 of file d3dx9shape.h.

Function Documentation

◆ D3DXCreateBox()

HRESULT WINAPI D3DXCreateBox ( struct IDirect3DDevice9 *  device,
float  width,
float  height,
float  depth,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency 
)

Definition at line 4653 of file mesh.c.

4655{
4656 HRESULT hr;
4657 ID3DXMesh *box;
4658 struct vertex *vertices;
4659 WORD (*faces)[3];
4660 DWORD *adjacency_buf;
4661 unsigned int i, face;
4662 static const D3DXVECTOR3 unit_box[] =
4663 {
4664 {-0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, 0.5f}, {-0.5f, 0.5f, 0.5f}, {-0.5f, 0.5f, -0.5f},
4665 {-0.5f, 0.5f, -0.5f}, {-0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f}, { 0.5f, 0.5f, -0.5f},
4666 { 0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, 0.5f}, { 0.5f, -0.5f, 0.5f}, { 0.5f, -0.5f, -0.5f},
4667 {-0.5f, -0.5f, 0.5f}, {-0.5f, -0.5f, -0.5f}, { 0.5f, -0.5f, -0.5f}, { 0.5f, -0.5f, 0.5f},
4668 {-0.5f, -0.5f, 0.5f}, { 0.5f, -0.5f, 0.5f}, { 0.5f, 0.5f, 0.5f}, {-0.5f, 0.5f, 0.5f},
4669 {-0.5f, -0.5f, -0.5f}, {-0.5f, 0.5f, -0.5f}, { 0.5f, 0.5f, -0.5f}, { 0.5f, -0.5f, -0.5f}
4670 };
4671 static const D3DXVECTOR3 normals[] =
4672 {
4673 {-1.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f}, { 1.0f, 0.0f, 0.0f},
4674 { 0.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, { 0.0f, 0.0f, -1.0f}
4675 };
4676 static const DWORD adjacency_table[] =
4677 {
4678 6, 9, 1, 2, 10, 0, 1, 9, 3, 4, 10, 2,
4679 3, 8, 5, 7, 11, 4, 0, 11, 7, 5, 8, 6,
4680 7, 4, 9, 2, 0, 8, 1, 3, 11, 5, 6, 10
4681 };
4682
4683 TRACE("device %p, width %f, height %f, depth %f, mesh %p, adjacency %p\n",
4684 device, width, height, depth, mesh, adjacency);
4685
4686 if (!device || width < 0.0f || height < 0.0f || depth < 0.0f || !mesh)
4687 {
4688 return D3DERR_INVALIDCALL;
4689 }
4690
4692 {
4693 return hr;
4694 }
4695
4696 if (FAILED(hr = box->lpVtbl->LockVertexBuffer(box, 0, (void **)&vertices)))
4697 {
4698 box->lpVtbl->Release(box);
4699 return hr;
4700 }
4701
4702 if (FAILED(hr = box->lpVtbl->LockIndexBuffer(box, 0, (void **)&faces)))
4703 {
4704 box->lpVtbl->UnlockVertexBuffer(box);
4705 box->lpVtbl->Release(box);
4706 return hr;
4707 }
4708
4709 for (i = 0; i < 24; i++)
4710 {
4711 vertices[i].position.x = width * unit_box[i].x;
4712 vertices[i].position.y = height * unit_box[i].y;
4713 vertices[i].position.z = depth * unit_box[i].z;
4714 vertices[i].normal.x = normals[i / 4].x;
4715 vertices[i].normal.y = normals[i / 4].y;
4716 vertices[i].normal.z = normals[i / 4].z;
4717 }
4718
4719 face = 0;
4720 for (i = 0; i < 12; i++)
4721 {
4722 faces[i][0] = face++;
4723 faces[i][1] = face++;
4724 faces[i][2] = (i % 2) ? face - 4 : face;
4725 }
4726
4727 box->lpVtbl->UnlockIndexBuffer(box);
4728 box->lpVtbl->UnlockVertexBuffer(box);
4729
4730 if (adjacency)
4731 {
4732 if (FAILED(hr = D3DXCreateBuffer(sizeof(adjacency_table), adjacency)))
4733 {
4734 box->lpVtbl->Release(box);
4735 return hr;
4736 }
4737
4738 adjacency_buf = ID3DXBuffer_GetBufferPointer(*adjacency);
4739 memcpy(adjacency_buf, adjacency_table, sizeof(adjacency_table));
4740 }
4741
4742 *mesh = box;
4743
4744 return D3D_OK;
4745}
#define D3DFVF_XYZ
Definition: d3d8types.h:113
#define D3DFVF_NORMAL
Definition: d3d8types.h:120
#define D3D_OK
Definition: d3d.h:106
#define D3DERR_INVALIDCALL
#define ID3DXBuffer_GetBufferPointer(p)
Definition: d3dx9core.h:85
@ D3DXMESH_MANAGED
Definition: d3dx9mesh.h:64
HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
Definition: core.c:131
HRESULT WINAPI D3DXCreateMeshFVF(DWORD numfaces, DWORD numvertices, DWORD options, DWORD fvf, struct IDirect3DDevice9 *device, struct ID3DXMesh **mesh)
Definition: mesh.c:2596
WORD face[3]
Definition: mesh.c:4747
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FAILED(hr)
Definition: intsafe.h:51
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
Definition: palette.c:468
Definition: devices.h:37
Definition: mesh.c:198
Definition: mesh.c:4558

Referenced by D3DXCreateBoxTest(), test_box(), and test_compute_normals().

◆ D3DXCreateCylinder()

HRESULT WINAPI D3DXCreateCylinder ( struct IDirect3DDevice9 *  device,
float  radius1,
float  radius2,
float  length,
UINT  slices,
UINT  stacks,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency 
)

Definition at line 4975 of file mesh.c.

4977{
4978 DWORD number_of_vertices, number_of_faces;
4979 HRESULT hr;
4980 ID3DXMesh *cylinder;
4981 struct vertex *vertices;
4982 face *faces;
4983 float theta_step, theta_start;
4984 struct sincos_table theta;
4985 float delta_radius, radius, radius_step;
4986 float z, z_step, z_normal;
4988
4989 TRACE("(%p, %f, %f, %f, %u, %u, %p, %p)\n", device, radius1, radius2, length, slices, stacks, mesh, adjacency);
4990
4991 if (device == NULL || radius1 < 0.0f || radius2 < 0.0f || length < 0.0f || slices < 2 || stacks < 1 || mesh == NULL)
4992 {
4993 return D3DERR_INVALIDCALL;
4994 }
4995
4996 number_of_vertices = 2 + (slices * (3 + stacks));
4997 number_of_faces = 2 * slices + stacks * (2 * slices);
4998
4999 hr = D3DXCreateMeshFVF(number_of_faces, number_of_vertices, D3DXMESH_MANAGED,
5001 if (FAILED(hr))
5002 {
5003 return hr;
5004 }
5005
5006 if (FAILED(hr = cylinder->lpVtbl->LockVertexBuffer(cylinder, 0, (void **)&vertices)))
5007 {
5008 cylinder->lpVtbl->Release(cylinder);
5009 return hr;
5010 }
5011
5012 if (FAILED(hr = cylinder->lpVtbl->LockIndexBuffer(cylinder, 0, (void **)&faces)))
5013 {
5014 cylinder->lpVtbl->UnlockVertexBuffer(cylinder);
5015 cylinder->lpVtbl->Release(cylinder);
5016 return hr;
5017 }
5018
5019 /* theta = angle on xy plane wrt x axis */
5020 theta_step = -2.0f * D3DX_PI / slices;
5021 theta_start = D3DX_PI / 2.0f;
5022
5023 if (!compute_sincos_table(&theta, theta_start, theta_step, slices))
5024 {
5025 cylinder->lpVtbl->UnlockIndexBuffer(cylinder);
5026 cylinder->lpVtbl->UnlockVertexBuffer(cylinder);
5027 cylinder->lpVtbl->Release(cylinder);
5028 return E_OUTOFMEMORY;
5029 }
5030
5031 vertex = 0;
5032 face = 0;
5033
5034 delta_radius = radius1 - radius2;
5035 radius = radius1;
5036 radius_step = delta_radius / stacks;
5037
5038 z = -length / 2;
5039 z_step = length / stacks;
5040 z_normal = delta_radius / length;
5041 if (isnan(z_normal))
5042 {
5043 z_normal = 0.0f;
5044 }
5045
5046 vertices[vertex].normal.x = 0.0f;
5047 vertices[vertex].normal.y = 0.0f;
5048 vertices[vertex].normal.z = -1.0f;
5049 vertices[vertex].position.x = 0.0f;
5050 vertices[vertex].position.y = 0.0f;
5051 vertices[vertex++].position.z = z;
5052
5053 for (slice = 0; slice < slices; slice++, vertex++)
5054 {
5055 vertices[vertex].normal.x = 0.0f;
5056 vertices[vertex].normal.y = 0.0f;
5057 vertices[vertex].normal.z = -1.0f;
5058 vertices[vertex].position.x = radius * theta.cos[slice];
5059 vertices[vertex].position.y = radius * theta.sin[slice];
5060 vertices[vertex].position.z = z;
5061
5062 if (slice > 0)
5063 {
5064 faces[face][0] = 0;
5065 faces[face][1] = slice;
5066 faces[face++][2] = slice + 1;
5067 }
5068 }
5069
5070 faces[face][0] = 0;
5071 faces[face][1] = slice;
5072 faces[face++][2] = 1;
5073
5074 for (stack = 1; stack <= stacks+1; stack++)
5075 {
5076 for (slice = 0; slice < slices; slice++, vertex++)
5077 {
5078 vertices[vertex].normal.x = theta.cos[slice];
5079 vertices[vertex].normal.y = theta.sin[slice];
5080 vertices[vertex].normal.z = z_normal;
5081 D3DXVec3Normalize(&vertices[vertex].normal, &vertices[vertex].normal);
5082 vertices[vertex].position.x = radius * theta.cos[slice];
5083 vertices[vertex].position.y = radius * theta.sin[slice];
5084 vertices[vertex].position.z = z;
5085
5086 if (stack > 1 && slice > 0)
5087 {
5088 faces[face][0] = vertex_index(slices, slice-1, stack-1);
5089 faces[face][1] = vertex_index(slices, slice-1, stack);
5090 faces[face++][2] = vertex_index(slices, slice, stack-1);
5091
5092 faces[face][0] = vertex_index(slices, slice, stack-1);
5093 faces[face][1] = vertex_index(slices, slice-1, stack);
5094 faces[face++][2] = vertex_index(slices, slice, stack);
5095 }
5096 }
5097
5098 if (stack > 1)
5099 {
5100 faces[face][0] = vertex_index(slices, slice-1, stack-1);
5101 faces[face][1] = vertex_index(slices, slice-1, stack);
5102 faces[face++][2] = vertex_index(slices, 0, stack-1);
5103
5104 faces[face][0] = vertex_index(slices, 0, stack-1);
5105 faces[face][1] = vertex_index(slices, slice-1, stack);
5106 faces[face++][2] = vertex_index(slices, 0, stack);
5107 }
5108
5109 if (stack < stacks + 1)
5110 {
5111 z += z_step;
5112 radius -= radius_step;
5113 }
5114 }
5115
5116 for (slice = 0; slice < slices; slice++, vertex++)
5117 {
5118 vertices[vertex].normal.x = 0.0f;
5119 vertices[vertex].normal.y = 0.0f;
5120 vertices[vertex].normal.z = 1.0f;
5121 vertices[vertex].position.x = radius * theta.cos[slice];
5122 vertices[vertex].position.y = radius * theta.sin[slice];
5123 vertices[vertex].position.z = z;
5124
5125 if (slice > 0)
5126 {
5127 faces[face][0] = vertex_index(slices, slice-1, stack);
5128 faces[face][1] = number_of_vertices - 1;
5129 faces[face++][2] = vertex_index(slices, slice, stack);
5130 }
5131 }
5132
5133 vertices[vertex].position.x = 0.0f;
5134 vertices[vertex].position.y = 0.0f;
5135 vertices[vertex].position.z = z;
5136 vertices[vertex].normal.x = 0.0f;
5137 vertices[vertex].normal.y = 0.0f;
5138 vertices[vertex].normal.z = 1.0f;
5139
5140 faces[face][0] = vertex_index(slices, slice-1, stack);
5141 faces[face][1] = number_of_vertices - 1;
5142 faces[face][2] = vertex_index(slices, 0, stack);
5143
5144 free_sincos_table(&theta);
5145 cylinder->lpVtbl->UnlockIndexBuffer(cylinder);
5146 cylinder->lpVtbl->UnlockVertexBuffer(cylinder);
5147
5148 if (adjacency)
5149 {
5150 if (FAILED(hr = D3DXCreateBuffer(number_of_faces * sizeof(DWORD) * 3, adjacency)))
5151 {
5152 cylinder->lpVtbl->Release(cylinder);
5153 return hr;
5154 }
5155
5156 if (FAILED(hr = cylinder->lpVtbl->GenerateAdjacency(cylinder, 0.0f, (*adjacency)->lpVtbl->GetBufferPointer(*adjacency))))
5157 {
5158 (*adjacency)->lpVtbl->Release(*adjacency);
5159 cylinder->lpVtbl->Release(cylinder);
5160 return hr;
5161 }
5162 }
5163
5164 *mesh = cylinder;
5165
5166 return D3D_OK;
5167}
Definition: _stack.h:55
GLUquadricObj * cylinder
Definition: cylfrac.c:44
#define D3DX_PI
Definition: d3dx9math.h:27
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
D3DXVECTOR3 *WINAPI D3DXVec3Normalize(D3DXVECTOR3 *pout, const D3DXVECTOR3 *pv)
Definition: math.c:1805
static void free_sincos_table(struct sincos_table *sincos_table)
Definition: mesh.c:4755
static BOOL compute_sincos_table(struct sincos_table *sincos_table, float angle_start, float angle_step, int n)
Definition: mesh.c:4762
static WORD vertex_index(UINT slices, int slice, int stack)
Definition: mesh.c:4790
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLdouble GLdouble z
Definition: glext.h:5874
ULONG Release()
#define isnan(x)
Definition: mingw_math.h:133
@ normal
Definition: optimize.h:166

Referenced by D3DXCreateCylinderTest(), and test_cylinder().

◆ D3DXCreatePolygon()

HRESULT WINAPI D3DXCreatePolygon ( struct IDirect3DDevice9 *  device,
float  length,
UINT  sides,
struct ID3DXMesh **  mesh,
ID3DXBuffer **  adjacency 
)

Definition at line 4563 of file mesh.c.

4565{
4566 HRESULT hr;
4567 ID3DXMesh *polygon;
4568 struct vertex *vertices;
4569 WORD (*faces)[3];
4570 DWORD (*adjacency_buf)[3];
4571 float angle, scale;
4572 unsigned int i;
4573
4574 TRACE("device %p, length %f, sides %u, mesh %p, adjacency %p.\n",
4575 device, length, sides, mesh, adjacency);
4576
4577 if (!device || length < 0.0f || sides < 3 || !mesh)
4578 return D3DERR_INVALIDCALL;
4579
4580 if (FAILED(hr = D3DXCreateMeshFVF(sides, sides + 1, D3DXMESH_MANAGED,
4581 D3DFVF_XYZ | D3DFVF_NORMAL, device, &polygon)))
4582 {
4583 return hr;
4584 }
4585
4586 if (FAILED(hr = polygon->lpVtbl->LockVertexBuffer(polygon, 0, (void **)&vertices)))
4587 {
4588 polygon->lpVtbl->Release(polygon);
4589 return hr;
4590 }
4591
4592 if (FAILED(hr = polygon->lpVtbl->LockIndexBuffer(polygon, 0, (void **)&faces)))
4593 {
4594 polygon->lpVtbl->UnlockVertexBuffer(polygon);
4595 polygon->lpVtbl->Release(polygon);
4596 return hr;
4597 }
4598
4599 angle = D3DX_PI / sides;
4600 scale = 0.5f * length / sinf(angle);
4601 angle *= 2.0f;
4602
4603 vertices[0].position.x = 0.0f;
4604 vertices[0].position.y = 0.0f;
4605 vertices[0].position.z = 0.0f;
4606 vertices[0].normal.x = 0.0f;
4607 vertices[0].normal.y = 0.0f;
4608 vertices[0].normal.z = 1.0f;
4609
4610 for (i = 0; i < sides; ++i)
4611 {
4612 vertices[i + 1].position.x = cosf(angle * i) * scale;
4613 vertices[i + 1].position.y = sinf(angle * i) * scale;
4614 vertices[i + 1].position.z = 0.0f;
4615 vertices[i + 1].normal.x = 0.0f;
4616 vertices[i + 1].normal.y = 0.0f;
4617 vertices[i + 1].normal.z = 1.0f;
4618
4619 faces[i][0] = 0;
4620 faces[i][1] = i + 1;
4621 faces[i][2] = i + 2;
4622 }
4623
4624 faces[sides - 1][2] = 1;
4625
4626 polygon->lpVtbl->UnlockVertexBuffer(polygon);
4627 polygon->lpVtbl->UnlockIndexBuffer(polygon);
4628
4629 if (adjacency)
4630 {
4631 if (FAILED(hr = D3DXCreateBuffer(sides * sizeof(DWORD) * 3, adjacency)))
4632 {
4633 polygon->lpVtbl->Release(polygon);
4634 return hr;
4635 }
4636
4637 adjacency_buf = ID3DXBuffer_GetBufferPointer(*adjacency);
4638 for (i = 0; i < sides; ++i)
4639 {
4640 adjacency_buf[i][0] = i - 1;
4641 adjacency_buf[i][1] = ~0U;
4642 adjacency_buf[i][2] = i + 1;
4643 }
4644 adjacency_buf[0][0] = sides - 1;
4645 adjacency_buf[sides - 1][2] = 0;
4646 }
4647
4648 *mesh = polygon;
4649
4650 return D3D_OK;
4651}
#define U(x)
Definition: wordpad.c:45
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9032
GLfloat angle
Definition: glext.h:10853
_Check_return_ float __cdecl cosf(_In_ float x)
Definition: math.h:224
_Check_return_ float __cdecl sinf(_In_ float x)
Definition: math.h:233
nsrefcnt Release()
#define DWORD
Definition: nt_native.h:44

Referenced by D3DXCreatePolygonTest(), and test_polygon().

◆ D3DXCreateSphere()

HRESULT WINAPI D3DXCreateSphere ( struct IDirect3DDevice9 *  device,
float  radius,
UINT  slices,
UINT  stacks,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency 
)

Definition at line 4795 of file mesh.c.

4797{
4798 DWORD number_of_vertices, number_of_faces;
4799 HRESULT hr;
4800 ID3DXMesh *sphere;
4801 struct vertex *vertices;
4802 face *faces;
4803 float phi_step, phi_start;
4804 struct sincos_table phi;
4805 float theta_step, theta, sin_theta, cos_theta;
4807
4808 TRACE("(%p, %f, %u, %u, %p, %p)\n", device, radius, slices, stacks, mesh, adjacency);
4809
4810 if (!device || radius < 0.0f || slices < 2 || stacks < 2 || !mesh)
4811 {
4812 return D3DERR_INVALIDCALL;
4813 }
4814
4815 number_of_vertices = 2 + slices * (stacks-1);
4816 number_of_faces = 2 * slices + (stacks - 2) * (2 * slices);
4817
4818 hr = D3DXCreateMeshFVF(number_of_faces, number_of_vertices, D3DXMESH_MANAGED,
4819 D3DFVF_XYZ | D3DFVF_NORMAL, device, &sphere);
4820 if (FAILED(hr))
4821 {
4822 return hr;
4823 }
4824
4825 if (FAILED(hr = sphere->lpVtbl->LockVertexBuffer(sphere, 0, (void **)&vertices)))
4826 {
4827 sphere->lpVtbl->Release(sphere);
4828 return hr;
4829 }
4830
4831 if (FAILED(hr = sphere->lpVtbl->LockIndexBuffer(sphere, 0, (void **)&faces)))
4832 {
4833 sphere->lpVtbl->UnlockVertexBuffer(sphere);
4834 sphere->lpVtbl->Release(sphere);
4835 return hr;
4836 }
4837
4838 /* phi = angle on xz plane wrt z axis */
4839 phi_step = -2.0f * D3DX_PI / slices;
4840 phi_start = D3DX_PI / 2.0f;
4841
4842 if (!compute_sincos_table(&phi, phi_start, phi_step, slices))
4843 {
4844 sphere->lpVtbl->UnlockIndexBuffer(sphere);
4845 sphere->lpVtbl->UnlockVertexBuffer(sphere);
4846 sphere->lpVtbl->Release(sphere);
4847 return E_OUTOFMEMORY;
4848 }
4849
4850 /* theta = angle on xy plane wrt x axis */
4851 theta_step = D3DX_PI / stacks;
4852 theta = theta_step;
4853
4854 vertex = 0;
4855 face = 0;
4856
4857 vertices[vertex].normal.x = 0.0f;
4858 vertices[vertex].normal.y = 0.0f;
4859 vertices[vertex].normal.z = 1.0f;
4860 vertices[vertex].position.x = 0.0f;
4861 vertices[vertex].position.y = 0.0f;
4862 vertices[vertex].position.z = radius;
4863 vertex++;
4864
4865 for (stack = 0; stack < stacks - 1; stack++)
4866 {
4867 sin_theta = sinf(theta);
4868 cos_theta = cosf(theta);
4869
4870 for (slice = 0; slice < slices; slice++)
4871 {
4872 vertices[vertex].normal.x = sin_theta * phi.cos[slice];
4873 vertices[vertex].normal.y = sin_theta * phi.sin[slice];
4874 vertices[vertex].normal.z = cos_theta;
4875 vertices[vertex].position.x = radius * sin_theta * phi.cos[slice];
4876 vertices[vertex].position.y = radius * sin_theta * phi.sin[slice];
4877 vertices[vertex].position.z = radius * cos_theta;
4878 vertex++;
4879
4880 if (slice > 0)
4881 {
4882 if (stack == 0)
4883 {
4884 /* top stack is triangle fan */
4885 faces[face][0] = 0;
4886 faces[face][1] = slice + 1;
4887 faces[face][2] = slice;
4888 face++;
4889 }
4890 else
4891 {
4892 /* stacks in between top and bottom are quad strips */
4893 faces[face][0] = vertex_index(slices, slice-1, stack-1);
4894 faces[face][1] = vertex_index(slices, slice, stack-1);
4895 faces[face][2] = vertex_index(slices, slice-1, stack);
4896 face++;
4897
4898 faces[face][0] = vertex_index(slices, slice, stack-1);
4899 faces[face][1] = vertex_index(slices, slice, stack);
4900 faces[face][2] = vertex_index(slices, slice-1, stack);
4901 face++;
4902 }
4903 }
4904 }
4905
4906 theta += theta_step;
4907
4908 if (stack == 0)
4909 {
4910 faces[face][0] = 0;
4911 faces[face][1] = 1;
4912 faces[face][2] = slice;
4913 face++;
4914 }
4915 else
4916 {
4917 faces[face][0] = vertex_index(slices, slice-1, stack-1);
4918 faces[face][1] = vertex_index(slices, 0, stack-1);
4919 faces[face][2] = vertex_index(slices, slice-1, stack);
4920 face++;
4921
4922 faces[face][0] = vertex_index(slices, 0, stack-1);
4923 faces[face][1] = vertex_index(slices, 0, stack);
4924 faces[face][2] = vertex_index(slices, slice-1, stack);
4925 face++;
4926 }
4927 }
4928
4929 vertices[vertex].position.x = 0.0f;
4930 vertices[vertex].position.y = 0.0f;
4931 vertices[vertex].position.z = -radius;
4932 vertices[vertex].normal.x = 0.0f;
4933 vertices[vertex].normal.y = 0.0f;
4934 vertices[vertex].normal.z = -1.0f;
4935
4936 /* bottom stack is triangle fan */
4937 for (slice = 1; slice < slices; slice++)
4938 {
4939 faces[face][0] = vertex_index(slices, slice-1, stack-1);
4940 faces[face][1] = vertex_index(slices, slice, stack-1);
4941 faces[face][2] = vertex;
4942 face++;
4943 }
4944
4945 faces[face][0] = vertex_index(slices, slice-1, stack-1);
4946 faces[face][1] = vertex_index(slices, 0, stack-1);
4947 faces[face][2] = vertex;
4948
4949 free_sincos_table(&phi);
4950 sphere->lpVtbl->UnlockIndexBuffer(sphere);
4951 sphere->lpVtbl->UnlockVertexBuffer(sphere);
4952
4953
4954 if (adjacency)
4955 {
4956 if (FAILED(hr = D3DXCreateBuffer(number_of_faces * sizeof(DWORD) * 3, adjacency)))
4957 {
4958 sphere->lpVtbl->Release(sphere);
4959 return hr;
4960 }
4961
4962 if (FAILED(hr = sphere->lpVtbl->GenerateAdjacency(sphere, 0.0f, (*adjacency)->lpVtbl->GetBufferPointer(*adjacency))))
4963 {
4964 (*adjacency)->lpVtbl->Release(*adjacency);
4965 sphere->lpVtbl->Release(sphere);
4966 return hr;
4967 }
4968 }
4969
4970 *mesh = sphere;
4971
4972 return D3D_OK;
4973}

Referenced by D3DXCreateSphereTest(), D3DXCreateTeapot(), test_compute_normals(), and test_sphere().

◆ D3DXCreateTeapot()

HRESULT WINAPI D3DXCreateTeapot ( struct IDirect3DDevice9 *  device,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency 
)

Definition at line 5169 of file mesh.c.

5171{
5172 FIXME("device %p, mesh %p, adjacency %p semi-stub.\n", device, mesh, adjacency);
5173
5174 return D3DXCreateSphere(device, 1.0f, 4, 4, mesh, adjacency);
5175}
#define FIXME(fmt,...)
Definition: debug.h:111
HRESULT WINAPI D3DXCreateSphere(struct IDirect3DDevice9 *device, float radius, UINT slices, UINT stacks, struct ID3DXMesh **mesh, struct ID3DXBuffer **adjacency)
Definition: mesh.c:4795

◆ D3DXCreateTextA()

HRESULT WINAPI D3DXCreateTextA ( struct IDirect3DDevice9 *  device,
HDC  hdc,
const char text,
float  deviation,
float  extrusion,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency,
GLYPHMETRICSFLOAT glyphmetrics 
)

Definition at line 5177 of file mesh.c.

5179{
5180 WCHAR *textW;
5181 HRESULT hr;
5182 int len;
5183
5184 TRACE("device %p, hdc %p, text %s, deviation %.8e, extrusion %.8e, mesh %p, adjacency %p, glyphmetrics %p.\n",
5185 device, hdc, debugstr_a(text), deviation, extrusion, mesh, adjacency, glyphmetrics);
5186
5187 if (!text)
5188 return D3DERR_INVALIDCALL;
5189
5190 len = MultiByteToWideChar(CP_ACP, 0, text, -1, NULL, 0);
5191 textW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
5193
5194 hr = D3DXCreateTextW(device, hdc, textW, deviation, extrusion,
5195 mesh, adjacency, glyphmetrics);
5197
5198 return hr;
5199}
HRESULT WINAPI D3DXCreateTextW(struct IDirect3DDevice9 *device, HDC hdc, const WCHAR *text, float deviation, float extrusion, struct ID3DXMesh **mesh_ptr, struct ID3DXBuffer **adjacency, GLYPHMETRICSFLOAT *glyphmetrics)
Definition: mesh.c:6094
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
const WCHAR * text
Definition: package.c:1799
GLenum GLsizei len
Definition: glext.h:6722
#define debugstr_a
Definition: kernel32.h:31
HDC hdc
Definition: main.c:9
static const WCHAR textW[]
Definition: itemdlg.c:1559
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by D3DXCreateTextTest(), and test_createtext().

◆ D3DXCreateTextW()

HRESULT WINAPI D3DXCreateTextW ( struct IDirect3DDevice9 *  device,
HDC  hdc,
const WCHAR text,
float  deviation,
FLOAT  extrusion,
struct ID3DXMesh **  mesh,
struct ID3DXBuffer **  adjacency,
GLYPHMETRICSFLOAT glyphmetrics 
)

Definition at line 6094 of file mesh.c.

6096{
6097 HRESULT hr;
6098 ID3DXMesh *mesh = NULL;
6099 DWORD nb_vertices, nb_faces;
6100 DWORD nb_front_faces, nb_corners, nb_outline_points;
6101 struct vertex *vertices = NULL;
6102 face *faces = NULL;
6103 int textlen = 0;
6104 float offset_x;
6105 LOGFONTW lf;
6107 HFONT font = NULL, oldfont = NULL;
6108 const MAT2 identity = {{0, 1}, {0, 0}, {0, 0}, {0, 1}};
6109 void *raw_outline = NULL;
6110 int bufsize = 0;
6111 struct glyphinfo *glyphs = NULL;
6112 GLYPHMETRICS gm;
6113 struct triangulation_array triangulations = {0, 0, NULL};
6114 int i;
6115 struct vertex *vertex_ptr;
6116 face *face_ptr;
6117 float max_deviation_sq;
6118 const struct cos_table cos_table = {
6119 cosf(D3DXToRadian(0.5f)),
6120 cosf(D3DXToRadian(45.0f)),
6121 cosf(D3DXToRadian(90.0f)),
6122 };
6123 int f1, f2;
6124
6125 TRACE("(%p, %p, %s, %f, %f, %p, %p, %p)\n", device, hdc,
6126 debugstr_w(text), deviation, extrusion, mesh_ptr, adjacency, glyphmetrics);
6127
6128 if (!device || !hdc || !text || !*text || deviation < 0.0f || extrusion < 0.0f || !mesh_ptr)
6129 return D3DERR_INVALIDCALL;
6130
6131 if (adjacency)
6132 {
6133 FIXME("Case of adjacency != NULL not implemented.\n");
6134 return E_NOTIMPL;
6135 }
6136
6137 if (!GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf) ||
6138 !GetOutlineTextMetricsW(hdc, sizeof(otm), &otm))
6139 {
6140 return D3DERR_INVALIDCALL;
6141 }
6142
6143 if (deviation == 0.0f)
6144 deviation = 1.0f / otm.otmEMSquare;
6145 max_deviation_sq = deviation * deviation;
6146
6147 lf.lfHeight = otm.otmEMSquare;
6148 lf.lfWidth = 0;
6150 if (!font) {
6151 hr = E_OUTOFMEMORY;
6152 goto error;
6153 }
6154 oldfont = SelectObject(hdc, font);
6155
6156 textlen = lstrlenW(text);
6157 for (i = 0; i < textlen; i++)
6158 {
6160 if (datasize < 0)
6161 return D3DERR_INVALIDCALL;
6162 if (bufsize < datasize)
6163 bufsize = datasize;
6164 }
6165 if (!bufsize) { /* e.g. text == " " */
6167 goto error;
6168 }
6169
6170 glyphs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, textlen * sizeof(*glyphs));
6171 raw_outline = HeapAlloc(GetProcessHeap(), 0, bufsize);
6172 if (!glyphs || !raw_outline) {
6173 hr = E_OUTOFMEMORY;
6174 goto error;
6175 }
6176
6177 offset_x = 0.0f;
6178 for (i = 0; i < textlen; i++)
6179 {
6180 /* get outline points from data returned from GetGlyphOutline */
6181 int datasize;
6182
6183 glyphs[i].offset_x = offset_x;
6184
6185 datasize = GetGlyphOutlineW(hdc, text[i], GGO_NATIVE, &gm, bufsize, raw_outline, &identity);
6186 hr = create_outline(&glyphs[i], raw_outline, datasize,
6187 max_deviation_sq, otm.otmEMSquare, &cos_table);
6188 if (hr != S_OK) goto error;
6189
6190 triangulations.glyph = &glyphs[i];
6191 hr = triangulate(&triangulations);
6192 if (hr != S_OK) goto error;
6193 if (triangulations.count) {
6194 ERR("%d incomplete triangulations of glyph (%u).\n", triangulations.count, text[i]);
6195 triangulations.count = 0;
6196 }
6197
6198 if (glyphmetrics)
6199 {
6200 glyphmetrics[i].gmfBlackBoxX = gm.gmBlackBoxX / (float)otm.otmEMSquare;
6201 glyphmetrics[i].gmfBlackBoxY = gm.gmBlackBoxY / (float)otm.otmEMSquare;
6202 glyphmetrics[i].gmfptGlyphOrigin.x = gm.gmptGlyphOrigin.x / (float)otm.otmEMSquare;
6203 glyphmetrics[i].gmfptGlyphOrigin.y = gm.gmptGlyphOrigin.y / (float)otm.otmEMSquare;
6204 glyphmetrics[i].gmfCellIncX = gm.gmCellIncX / (float)otm.otmEMSquare;
6205 glyphmetrics[i].gmfCellIncY = gm.gmCellIncY / (float)otm.otmEMSquare;
6206 }
6207 offset_x += gm.gmCellIncX / (float)otm.otmEMSquare;
6208 }
6209
6210 /* corner points need an extra vertex for the different side faces normals */
6211 nb_corners = 0;
6212 nb_outline_points = 0;
6213 nb_front_faces = 0;
6214 for (i = 0; i < textlen; i++)
6215 {
6216 int j;
6217 nb_outline_points += glyphs[i].ordered_vertices.count;
6218 nb_front_faces += glyphs[i].faces.count;
6219 for (j = 0; j < glyphs[i].outlines.count; j++)
6220 {
6221 int k;
6222 struct outline *outline = &glyphs[i].outlines.items[j];
6223 nb_corners++; /* first outline point always repeated as a corner */
6224 for (k = 1; k < outline->count; k++)
6225 if (outline->items[k].corner)
6226 nb_corners++;
6227 }
6228 }
6229
6230 nb_vertices = (nb_outline_points + nb_corners) * 2 + nb_outline_points * 2;
6231 nb_faces = nb_outline_points * 2 + nb_front_faces * 2;
6232
6233
6234 hr = D3DXCreateMeshFVF(nb_faces, nb_vertices, D3DXMESH_MANAGED,
6236 if (FAILED(hr))
6237 goto error;
6238
6239 if (FAILED(hr = mesh->lpVtbl->LockVertexBuffer(mesh, 0, (void **)&vertices)))
6240 goto error;
6241
6242 if (FAILED(hr = mesh->lpVtbl->LockIndexBuffer(mesh, 0, (void **)&faces)))
6243 goto error;
6244
6245 /* convert 2D vertices and faces into 3D mesh */
6246 vertex_ptr = vertices;
6247 face_ptr = faces;
6248 if (extrusion == 0.0f) {
6249 f1 = 1;
6250 f2 = 2;
6251 } else {
6252 f1 = 2;
6253 f2 = 1;
6254 }
6255 for (i = 0; i < textlen; i++)
6256 {
6257 int j;
6258 int count;
6259 struct vertex *back_vertices;
6260 face *back_faces;
6261
6262 /* side vertices and faces */
6263 for (j = 0; j < glyphs[i].outlines.count; j++)
6264 {
6265 struct vertex *outline_vertices = vertex_ptr;
6266 struct outline *outline = &glyphs[i].outlines.items[j];
6267 int k;
6268 struct point2d *prevpt = &outline->items[outline->count - 1];
6269 struct point2d *pt = &outline->items[0];
6270
6271 for (k = 1; k <= outline->count; k++)
6272 {
6273 struct vertex vtx;
6274 struct point2d *nextpt = &outline->items[k % outline->count];
6275 WORD vtx_idx = vertex_ptr - vertices;
6277
6278 if (pt->corner == POINTTYPE_CURVE_START)
6279 D3DXVec2Subtract(&vec, &pt->pos, &prevpt->pos);
6280 else if (pt->corner)
6281 D3DXVec2Subtract(&vec, &nextpt->pos, &pt->pos);
6282 else
6283 D3DXVec2Subtract(&vec, &nextpt->pos, &prevpt->pos);
6285 vtx.normal.x = -vec.y;
6286 vtx.normal.y = vec.x;
6287 vtx.normal.z = 0;
6288
6289 vtx.position.x = pt->pos.x + glyphs[i].offset_x;
6290 vtx.position.y = pt->pos.y;
6291 vtx.position.z = 0;
6292 *vertex_ptr++ = vtx;
6293
6294 vtx.position.z = -extrusion;
6295 *vertex_ptr++ = vtx;
6296
6297 vtx.position.x = nextpt->pos.x + glyphs[i].offset_x;
6298 vtx.position.y = nextpt->pos.y;
6299 if (pt->corner && nextpt->corner && nextpt->corner != POINTTYPE_CURVE_END) {
6300 vtx.position.z = -extrusion;
6301 *vertex_ptr++ = vtx;
6302 vtx.position.z = 0;
6303 *vertex_ptr++ = vtx;
6304
6305 (*face_ptr)[0] = vtx_idx;
6306 (*face_ptr)[1] = vtx_idx + 2;
6307 (*face_ptr)[2] = vtx_idx + 1;
6308 face_ptr++;
6309
6310 (*face_ptr)[0] = vtx_idx;
6311 (*face_ptr)[1] = vtx_idx + 3;
6312 (*face_ptr)[2] = vtx_idx + 2;
6313 face_ptr++;
6314 } else {
6315 if (nextpt->corner) {
6316 if (nextpt->corner == POINTTYPE_CURVE_END) {
6317 D3DXVECTOR2 *nextpt2 = &outline->items[(k + 1) % outline->count].pos;
6318 D3DXVec2Subtract(&vec, nextpt2, &nextpt->pos);
6319 } else {
6320 D3DXVec2Subtract(&vec, &nextpt->pos, &pt->pos);
6321 }
6323 vtx.normal.x = -vec.y;
6324 vtx.normal.y = vec.x;
6325
6326 vtx.position.z = 0;
6327 *vertex_ptr++ = vtx;
6328 vtx.position.z = -extrusion;
6329 *vertex_ptr++ = vtx;
6330 }
6331
6332 (*face_ptr)[0] = vtx_idx;
6333 (*face_ptr)[1] = vtx_idx + 3;
6334 (*face_ptr)[2] = vtx_idx + 1;
6335 face_ptr++;
6336
6337 (*face_ptr)[0] = vtx_idx;
6338 (*face_ptr)[1] = vtx_idx + 2;
6339 (*face_ptr)[2] = vtx_idx + 3;
6340 face_ptr++;
6341 }
6342
6343 prevpt = pt;
6344 pt = nextpt;
6345 }
6346 if (!pt->corner) {
6347 *vertex_ptr++ = *outline_vertices++;
6348 *vertex_ptr++ = *outline_vertices++;
6349 }
6350 }
6351
6352 /* back vertices and faces */
6353 back_faces = face_ptr;
6354 back_vertices = vertex_ptr;
6355 for (j = 0; j < glyphs[i].ordered_vertices.count; j++)
6356 {
6358 vertex_ptr->position.x = pt->x + glyphs[i].offset_x;
6359 vertex_ptr->position.y = pt->y;
6360 vertex_ptr->position.z = 0;
6361 vertex_ptr->normal.x = 0;
6362 vertex_ptr->normal.y = 0;
6363 vertex_ptr->normal.z = 1;
6364 vertex_ptr++;
6365 }
6366 count = back_vertices - vertices;
6367 for (j = 0; j < glyphs[i].faces.count; j++)
6368 {
6369 face *f = &glyphs[i].faces.items[j];
6370 (*face_ptr)[0] = (*f)[0] + count;
6371 (*face_ptr)[1] = (*f)[1] + count;
6372 (*face_ptr)[2] = (*f)[2] + count;
6373 face_ptr++;
6374 }
6375
6376 /* front vertices and faces */
6377 j = count = vertex_ptr - back_vertices;
6378 while (j--)
6379 {
6380 vertex_ptr->position.x = back_vertices->position.x;
6381 vertex_ptr->position.y = back_vertices->position.y;
6382 vertex_ptr->position.z = -extrusion;
6383 vertex_ptr->normal.x = 0;
6384 vertex_ptr->normal.y = 0;
6385 vertex_ptr->normal.z = extrusion == 0.0f ? 1.0f : -1.0f;
6386 vertex_ptr++;
6387 back_vertices++;
6388 }
6389 j = face_ptr - back_faces;
6390 while (j--)
6391 {
6392 (*face_ptr)[0] = (*back_faces)[0] + count;
6393 (*face_ptr)[1] = (*back_faces)[f1] + count;
6394 (*face_ptr)[2] = (*back_faces)[f2] + count;
6395 face_ptr++;
6396 back_faces++;
6397 }
6398 }
6399
6400 *mesh_ptr = mesh;
6401 hr = D3D_OK;
6402error:
6403 if (mesh) {
6404 if (faces) mesh->lpVtbl->UnlockIndexBuffer(mesh);
6405 if (vertices) mesh->lpVtbl->UnlockVertexBuffer(mesh);
6406 if (hr != D3D_OK) mesh->lpVtbl->Release(mesh);
6407 }
6408 if (glyphs) {
6409 for (i = 0; i < textlen; i++)
6410 {
6411 int j;
6412 for (j = 0; j < glyphs[i].outlines.count; j++)
6413 HeapFree(GetProcessHeap(), 0, glyphs[i].outlines.items[j].items);
6414 HeapFree(GetProcessHeap(), 0, glyphs[i].outlines.items);
6415 HeapFree(GetProcessHeap(), 0, glyphs[i].faces.items);
6416 HeapFree(GetProcessHeap(), 0, glyphs[i].ordered_vertices.items);
6417 }
6419 }
6420 if (triangulations.items) {
6421 int i;
6422 for (i = 0; i < triangulations.count; i++)
6423 HeapFree(GetProcessHeap(), 0, triangulations.items[i].vertex_stack.items);
6424 HeapFree(GetProcessHeap(), 0, triangulations.items);
6425 }
6426 HeapFree(GetProcessHeap(), 0, raw_outline);
6427 if (oldfont) SelectObject(hdc, oldfont);
6428 if (font) DeleteObject(font);
6429
6430 return hr;
6431}
#define ERR(fmt,...)
Definition: debug.h:110
static SIZE_T datasize
Definition: asm.c:30
#define D3DXToRadian(degree)
Definition: d3dx9math.h:33
#define E_NOTIMPL
Definition: ddrawi.h:99
D3DXVECTOR2 *WINAPI D3DXVec2Normalize(D3DXVECTOR2 *pout, const D3DXVECTOR2 *pv)
Definition: math.c:1659
static HRESULT create_outline(struct glyphinfo *glyph, void *raw_outline, int datasize, float max_deviation_sq, unsigned int emsquare, const struct cos_table *cos_table)
Definition: mesh.c:5570
static HRESULT triangulate(struct triangulation_array *triangulations)
Definition: mesh.c:5858
@ POINTTYPE_CURVE_END
Definition: mesh.c:5312
@ POINTTYPE_CURVE_START
Definition: mesh.c:5311
static D3DXVECTOR2 * get_ordered_vertex(struct glyphinfo *glyph, WORD index)
Definition: mesh.c:5738
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define lstrlenW
Definition: compat.h:750
#define pt(x, y)
Definition: drawing.c:79
FT_Vector * vec
Definition: ftbbox.c:448
pKey DeleteObject()
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLfloat f
Definition: glext.h:7540
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define S_OK
Definition: intsafe.h:52
#define debugstr_w
Definition: kernel32.h:32
#define error(str)
Definition: mkdosfs.c:1605
static UINT UINT LPWORD glyphs
Definition: font.c:44
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
static float(__cdecl *square_half_float)(float x
int k
Definition: mpi.c:3369
Definition: mk_font.cpp:20
#define OBJ_FONT
Definition: objidl.idl:1414
#define f2(x, y, z)
Definition: sha1.c:31
#define f1(x, y, z)
Definition: sha1.c:30
FLOAT x
Definition: d3dx9math.h:64
FLOAT y
Definition: d3dx9math.h:64
FT_Pos x
Definition: ftimage.h:76
FT_Pos y
Definition: ftimage.h:77
LONG lfHeight
Definition: dimm.idl:59
LONG lfWidth
Definition: dimm.idl:60
FLOAT gmfBlackBoxX
Definition: wingdi.h:2726
POINTFLOAT gmfptGlyphOrigin
Definition: wingdi.h:2728
short gmCellIncX
Definition: wingdi.h:2445
UINT gmBlackBoxY
Definition: wingdi.h:2443
UINT gmBlackBoxX
Definition: wingdi.h:2442
short gmCellIncY
Definition: wingdi.h:2446
POINT gmptGlyphOrigin
Definition: wingdi.h:2444
Definition: wingdi.h:2472
FLOAT x
Definition: wingdi.h:2722
Definition: mesh.c:5330
struct point2d * items
Definition: mesh.c:5332
int count
Definition: mesh.c:5331
Definition: mesh.c:5317
D3DXVECTOR2 pos
Definition: mesh.c:5318
enum pointtype corner
Definition: mesh.c:5319
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
struct triangulation * items
Definition: mesh.c:5387
struct glyphinfo * glyph
Definition: mesh.c:5389
D3DXVECTOR3 normal
Definition: mesh.c:4560
D3DXVECTOR3 position
Definition: mesh.c:4559
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
HGDIOBJ WINAPI GetCurrentObject(_In_ HDC, _In_ UINT)
Definition: dc.c:428
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
UINT WINAPI GetOutlineTextMetricsW(_In_ HDC hdc, _In_ UINT cjCopy, _Out_writes_bytes_opt_(cjCopy) LPOUTLINETEXTMETRICW potm)
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
#define GGO_NATIVE
Definition: wingdi.h:850
DWORD WINAPI GetGlyphOutlineW(_In_ HDC hdc, _In_ UINT uChar, _In_ UINT fuFormat, _Out_ LPGLYPHMETRICS lpgm, _In_ DWORD cjBuffer, _Out_writes_bytes_opt_(cjBuffer) LPVOID pvBuffer, _In_ CONST MAT2 *lpmat2)

Referenced by D3DXCreateTextA(), and D3DXCreateTextTest().

◆ D3DXCreateTorus()

HRESULT WINAPI D3DXCreateTorus ( struct IDirect3DDevice9 *  device,
float  innerradius,
float  outerradius,
UINT  sides,
UINT  rings,
struct ID3DXMesh **  mesh,
ID3DXBuffer **  adjacency 
)

Definition at line 5201 of file mesh.c.

5203{
5204 HRESULT hr;
5205 ID3DXMesh *torus;
5206 WORD (*faces)[3];
5207 struct vertex *vertices;
5208 float phi, phi_step, sin_phi, cos_phi;
5209 float theta, theta_step, sin_theta, cos_theta;
5210 unsigned int i, j, numvert, numfaces;
5211
5212 TRACE("device %p, innerradius %.8e, outerradius %.8e, sides %u, rings %u, mesh %p, adjacency %p.\n",
5213 device, innerradius, outerradius, sides, rings, mesh, adjacency);
5214
5215 numvert = sides * rings;
5216 numfaces = numvert * 2;
5217
5218 if (!device || innerradius < 0.0f || outerradius < 0.0f || sides < 3 || rings < 3 || !mesh)
5219 {
5220 WARN("Invalid arguments.\n");
5221 return D3DERR_INVALIDCALL;
5222 }
5223
5224 if (FAILED(hr = D3DXCreateMeshFVF(numfaces, numvert, D3DXMESH_MANAGED, D3DFVF_XYZ | D3DFVF_NORMAL, device, &torus)))
5225 return hr;
5226
5227 if (FAILED(hr = torus->lpVtbl->LockVertexBuffer(torus, 0, (void **)&vertices)))
5228 {
5229 torus->lpVtbl->Release(torus);
5230 return hr;
5231 }
5232
5233 if (FAILED(hr = torus->lpVtbl->LockIndexBuffer(torus, 0, (void **)&faces)))
5234 {
5235 torus->lpVtbl->UnlockVertexBuffer(torus);
5236 torus->lpVtbl->Release(torus);
5237 return hr;
5238 }
5239
5240 phi_step = D3DX_PI / sides * 2.0f;
5241 theta_step = D3DX_PI / rings * -2.0f;
5242
5243 theta = 0.0f;
5244
5245 for (i = 0; i < rings; ++i)
5246 {
5247 phi = 0.0f;
5248
5249 sin_theta = sinf(theta);
5250 cos_theta = cosf(theta);
5251
5252 for (j = 0; j < sides; ++j)
5253 {
5254 sin_phi = sinf(phi);
5255 cos_phi = cosf(phi);
5256
5257 vertices[i * sides + j].position.x = (innerradius * cos_phi + outerradius) * cos_theta;
5258 vertices[i * sides + j].position.y = (innerradius * cos_phi + outerradius) * sin_theta;
5259 vertices[i * sides + j].position.z = innerradius * sin_phi;
5260 vertices[i * sides + j].normal.x = cos_phi * cos_theta;
5261 vertices[i * sides + j].normal.y = cos_phi * sin_theta;
5262 vertices[i * sides + j].normal.z = sin_phi;
5263
5264 phi += phi_step;
5265 }
5266
5267 theta += theta_step;
5268 }
5269
5270 for (i = 0; i < numfaces - sides * 2; ++i)
5271 {
5272 faces[i][0] = i % 2 ? i / 2 + sides : i / 2;
5273 faces[i][1] = (i / 2 + 1) % sides ? i / 2 + 1 : i / 2 + 1 - sides;
5274 faces[i][2] = (i + 1) % (sides * 2) ? (i + 1) / 2 + sides : (i + 1) / 2;
5275 }
5276
5277 for (j = 0; i < numfaces; ++i, ++j)
5278 {
5279 faces[i][0] = i % 2 ? j / 2 : i / 2;
5280 faces[i][1] = (i / 2 + 1) % sides ? i / 2 + 1 : i / 2 + 1 - sides;
5281 faces[i][2] = i == numfaces - 1 ? 0 : (j + 1) / 2;
5282 }
5283
5284 torus->lpVtbl->UnlockIndexBuffer(torus);
5285 torus->lpVtbl->UnlockVertexBuffer(torus);
5286
5287 if (adjacency)
5288 {
5289 if (FAILED(hr = D3DXCreateBuffer(numfaces * sizeof(DWORD) * 3, adjacency)))
5290 {
5291 torus->lpVtbl->Release(torus);
5292 return hr;
5293 }
5294
5295 if (FAILED(hr = torus->lpVtbl->GenerateAdjacency(torus, 0.0f, (*adjacency)->lpVtbl->GetBufferPointer(*adjacency))))
5296 {
5297 (*adjacency)->lpVtbl->Release(*adjacency);
5298 torus->lpVtbl->Release(torus);
5299 return hr;
5300 }
5301 }
5302
5303 *mesh = torus;
5304
5305 return D3D_OK;
5306}
#define WARN(fmt,...)
Definition: debug.h:112

Referenced by D3DXCreateTorusTest(), and test_torus().