在3D对象上方获取图片 [英] Get a picture above an 3D Object

查看:74
本文介绍了在3D对象上方获取图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正忙于创建跟随动作的眼睛.

像这个例子-
http://hackaday.com/2011/10/27/vigos -stare-follows-you-where-you-go/ [

Hello,

I''m busy with creating an eye that follows movements.

Like this example -
http://hackaday.com/2011/10/27/vigos-stare-follows-you-wherever-you-go/[^]

Everything works great.

But now I want to add a picture on it. Like the example.

Not as background but as front so that it looks like that the eye is in the picture.

My question is how can I do that.

Thanks a lot for helping

推荐答案

我发现了问题.
这是解决方案. (您找不到针对此问题的任何解决方案).

I have found the problem.
This is the solution. (you don''t find any solutions for this problem).

private Device device;
private Texture texture;
private Material material;
private Sprite sprite;
Surface s;
SurfaceDescription desc;
public Form1()
{
    InitializeComponent();
    this.SetStyle(ControlStyles.AllPaintingInWmPaint |
    ControlStyles.Opaque, true);
}

public void InitializeDevice()
{
    PresentParameters presentParams = new PresentParameters();
    presentParams.Windowed = true;
    presentParams.SwapEffect = SwapEffect.Discard;
    presentParams.AutoDepthStencilFormat = DepthFormat.D16;
    presentParams.EnableAutoDepthStencil = true;
    device = new Device(0, DeviceType.Hardware, this,
    CreateFlags.SoftwareVertexProcessing, presentParams);
    sprite = new Sprite(device);
    device.RenderState.Lighting = false;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
    device.RenderState.AlphaBlendEnable = true;
    device.RenderState.AlphaTestEnable = false;
    device.RenderState.SourceBlend = Blend.SourceAlpha;
    device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
    device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
    device.BeginScene();
    sprite.Begin(SpriteFlags.AlphaBlend);
    sprite.Draw2D(texture, new Point(0,0),0, new Point(0,0),
    Color.White); // you must set the color as white
    device.RenderState.AlphaBlendEnable = false;
    sprite.End();
    device.EndScene();
    device.Present();
    this.Invalidate();
}
public void LoadTexturesAndMaterials()
{
    material = new Material();
    material.Diffuse = Color.White;
    material.Specular = Color.LightGray;
    material.SpecularSharpness = 15.0F;
    device.Material = material;
    string path = Application.StartupPath;
    texture = TextureLoader.FromFile(device, @path + "\\image.png"
    // add this when you give a color on the transparent part.
    //like Fuchsia.
    /*, 1024, 768, 1, 0, Format.Unknown, Pool.Default, Filter.Linear,
    Filter.Linear,Color.Fuchsia.ToArgb()*/);
    s = texture.GetSurfaceLevel(0);
    desc = s.Description;
}


这篇关于在3D对象上方获取图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆