一个简单的图形处理问题,小弟刚学,请大哥些帮我看下。100分相赠。
其实很简单,就是一个瓶贴的效果,网上搜了很久,都没找到合适的,找到一个图刚好能描述我的要求,请大哥些帮帮忙啊。
程序处理效果说明:http://album.sina.com.cn/pic/4ce75b1a02000u5g
要求:
1.用delphi写,可以用第三方有源码的控件,当然,最好不用。
2.贴出处理的源代码,或者发到rsnlp@tom.com
非常感谢。
[解决办法]
这个貌似使用D3D建立个顶点缓冲模型再将你的图片作为纹理贴在那个弧度上比较简单
[解决办法]
up
[解决办法]
up
[解决办法]
delphi第三方好像有个控件可以做,我帮你找找。
[解决办法]
安装directx控件看看,我以前用过,觉得功能挺强大的,不知道可否满足你的要求
[解决办法]
不知道读点能不能解决,呵,,,,
我想了一下,,,先画一条红色的狐线,,,
然后,,,读狐线区域,,,
发现是红色的第一个X点的位置,,
就把图像的X=1, for y=1 to 图像.高度 do 一条竖边读出来,,从红色狐的位置开始描点,,
描完了后,,,,
又开始读红色狐线的第二个X点,
再把图像的X=2, for y=1 to 图像.高度 do 一条竖边读出来,,从红色狐的位置开始描点,,
......
[解决办法]
先画狐线的时候,可以多画几次,看看狐线能不能对应瓶子的狐度,,,呵,,
[解决办法]
DirectX8中的例子,演示将一张位图贴在一个圆桶上并旋转
准备一张banana.bmp的位图,需要用到的dx单元要到http://www.clootie.ru/下载
//-----------------------------------------
// File: Textures.cpp
//
// Desc: Better than just lights and materials, 3D objects look much more
// convincing when texture-mapped. Textures can be thought of as a sort
// of wallpaper, that is shrinkwrapped to fit a texture. Textures are
// typically loaded from image files, and D3DX provides a utility to
// function to do this for us. Like a vertex buffer, textures have
// Lock() and Unlock() functions to access (read or write) the image
// data. Textures have a width, height, miplevel, and pixel format. The
// miplevel is for "mipmapped " textures, an advanced performance-
// enhancing feature which uses lower resolutions of the texture for
// objects in the distance where detail is less noticeable. The pixel
// format determines how the colors are stored in a texel. The most
// common formats are the 16-bit R5G6B5 format (5 bits of red, 6-bits of
// green and 5 bits of blue) and the 32-bit A8R8G8B8 format (8 bits each
// of alpha, red, green, and blue).
//
// Textures are associated with geometry through texture coordinates.
// Each vertex has one or more sets of texture coordinates, which are
// named tu and tv and range from 0.0 to 1.0. Texture coordinates can be
// supplied by the geometry, or can be automatically generated using
// Direct3D texture coordinate generation (which is an advanced feature).
//-----------------------------------------
program Tut05_Textures;
uses
Windows,
Messages,
Direct3D8 in 'JEDI\Direct3D8.pas ',
DXTypes in 'JEDI\DXTypes.pas ',
DXFile in 'JEDI\DXFile.pas ',
D3DX8 in 'JEDI\D3DX8.pas ';
//-----------------------------------------
// Global variables
//-----------------------------------------
var
g_pD3D :IDirect3D8 = nil; // Used to create the D3DDevice
g_pd3dDevice:IDirect3DDevice8 = nil; // Our rendering device
g_pVB :IDirect3DVertexBuffer8 = nil; // Buffer to hold vertices
g_pTexture :IDirect3DTexture8 = nil; // Our texture
// A structure for our custom vertex type. We added texture coordinates
type
CUSTOMVERTEX=record
position:TD3DXVector3; // The position
color :TD3DColor; // The color
tu, tv :Single; // The texture coordinates
end;
// Our custom FVF, which describes our custom vertex structure
const D3DFVF_CUSTOMVERTEX = (D3DFVF_XYZ or D3DFVF_DIFFUSE or D3DFVF_TEX1);
//-----------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------
function InitD3D(hWnd: THandle) :HRESULT;
var
d3ddm :TD3DDisplayMode;
d3dpp :TD3DPresentParameters;
begin
// Create the D3D object.
g_pD3D:=Direct3DCreate8(D3D_SDK_VERSION);
if g_pD3D=nil then begin
Result:=E_FAIL;
exit;
end;
// Get the current desktop display mode, so we can set up a back
// buffer of the same format
if FAILED(g_pD3D.GetAdapterDisplayMode( D3DADAPTER_DEFAULT, d3ddm )) then begin
Result:=E_FAIL;
exit;
end;
// Set up the structure used to create the D3DDevice. Since we are now
// using more complex geometry, we will create a device with a zbuffer.
Fillchar(d3dpp, sizeof(d3dpp), 0);
d3dpp.Windowed := TRUE;
d3dpp.SwapEffect := D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat := d3ddm.Format;
d3dpp.EnableAutoDepthStencil := TRUE;
d3dpp.AutoDepthStencilFormat := D3DFMT_D16;
// Create the Direct3D device.
if FAILED(g_pD3D.CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
d3dpp, g_pd3dDevice )) then begin
Result:=E_FAIL;
exit;
end;
// Turn off culling
g_pd3dDevice.SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off D3D lighting
g_pd3dDevice.SetRenderState( D3DRS_LIGHTING, Ord(FALSE) );
// Turn on the zbuffer
g_pd3dDevice.SetRenderState( D3DRS_ZENABLE, Ord(TRUE) );
Result:=S_OK;
end;
//-----------------------------------------
// Name: InitGeometry()
// Desc: Creates the scene geometry
// 这段就是关键了
//-----------------------------------------
function InitGeometry :HRESULT;
var
pVertices,P:^CUSTOMVERTEX;
i:DWORD;
theta:Single;
begin
// Use D3DX to create a texture from a file based image
//载入位图
if FAILED(D3DXCreateTextureFromFile( g_pd3dDevice, 'banana.bmp ',
g_pTexture )) then begin
Result:=E_FAIL;
exit;
end;
// Create the vertex buffer.
//建立顶点缓冲
if FAILED(g_pd3dDevice.CreateVertexBuffer(50*2*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, g_pVB)) then begin
Result:=E_FAIL;
exit;
end;
// Fill the vertex buffer. We are setting the tu and tv texture
// coordinates, which range from 0.0 to 1.0
pVertices:=nil;
if FAILED(g_pVB.Lock(0, 0, PByte(pVertices), 0)) then begin
Result:=E_FAIL;
exit;
end;
//最关键的部分,建立一个圆桶
for i:=0 to 49 do begin
theta:=(2*D3DX_PI*i)/(50-1);
P:=pVertices;
Inc(P,2*i+0);
P.position := D3DXVECTOR3( sin(theta),-1.0, cos(theta) );
P.color := $FFFFFF;
P.tu := i/(50-1);
P.tv := 1.0;
P:=pVertices;
Inc(P,2*i+1);
P.position := D3DXVECTOR3( sin(theta),1.0, cos(theta) );
P.color := $808080;
P.tu := i/(50-1);
P.tv := 0;
end;
g_pVB.Unlock;
pVertices:=nil;
Result:=S_OK;
end;