[.net] Normal.Normalize() problem (C#)

Started by
9 comments, last by Flimflam 14 years ago
I have a problem with Normal.Normalize() method in CustomVertex.PositionNormal structure. It doesn't work for me at all. Here is a simple code which i use for testing: CustomVertex.PositionNormal[] verts; verts = new CustomVertex.PositionNormal[1]; verts[0].Normal = new Vector3(5, 0, 0); verts[0].Normal.Normalize(); In my case last line of the code does nothing at all. verts[0].Normal vector is stays unchanged (5, 0, 0). But if i try like this: Vector3 test = new Vector3(5, 0, 0); test.Normalize(); test vector becomes normalized as it should (1,0,0). So the question is am i doing something wrong or Normalize() method is broken in CustomVertex structures?
Advertisement
It's been a long time since I've used Managed DirectX (which is deprecated, long gone trash, by the way) but I'm guessing that Normal is a property, which means you have to set it. You can't just alter it in place like that.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Yes, it's indeed a property. So even if it has Normalize() method inherited from Vector3, it will not work because it's a property?

P.S. As for Managed DirectX being a trash, i'm aware of that. I'm beginner in C#. I chose Managed DirectX because i have an Windows Form application and i need to have a small control with 3D graphics inside the main window. I've found a couple of ready to use Managed DirectX controls which i could use, and began to learn Managed DirectX.
I thought that XNA is not suitable for such application, because it's targeted for games, which usually use whole window. If i'm wrong and it's possible to have an XNA control inside main program's window, please tell me.
Quote:
If i'm wrong and it's possible to have an XNA control inside main program's window, please tell me.

It's possible. There's also SlimDX.
Yeah, i know about SlimDX too, but i'm beginner and i couldn't find enough sample projects for it, only basic documentation. What do you recommend to use in my case? XNA or SlimDX?
Quote:Original post by Icos
Yes, it's indeed a property. So even if it has Normalize() method inherited from Vector3, it will not work because it's a property?

P.S. As for Managed DirectX being a trash, i'm aware of that. I'm beginner in C#. I chose Managed DirectX because i have an Windows Form application and i need to have a small control with 3D graphics inside the main window. I've found a couple of ready to use Managed DirectX controls which i could use, and began to learn Managed DirectX.
I thought that XNA is not suitable for such application, because it's targeted for games, which usually use whole window. If i'm wrong and it's possible to have an XNA control inside main program's window, please tell me.


It takes a bit of work (not too much, there's am easy sample on the XNA homepage) but it is easy to host XNA inside a control on a form. XNA is also much easier to develop for than SlimDX since it was designed with managed languages in mind, where as SlimDX is more just a wrapper for native C++.

Both of those options are far better than using Managed DirectX though.
Quote:
XNA is also much easier to develop for than SlimDX since it was designed with managed languages in mind, where as SlimDX is more just a wrapper for native C++.

That's not particularly accurate. XNA is easier to develop for/with because it's significantly higher level than SlimDX, and was designed with that in mind. SlimDX goes to great lengths to be an elegant managed library, and with a few minor exceptions does so very well. It's just by nature a lower level construct.
Quote:Original post by Icos
Yes, it's indeed a property. So even if it has Normalize() method inherited from Vector3, it will not work because it's a property?

Yes, this is caused by Vector3 being a struct, ergo it being a value type. When you read the property, you actually get a copy of the original Vector3 struct (not a reference to it), and by calling Normalize you just modify your copy, not the original.

What you'd need to do in this case is something like this:

verts[0].Normal = Vector3.Normalize(verts[0].Normal);
Thank you everybody for your answers. I'll look for a way to make an XNA control for my form then.
Original post by Flimflam
Quote:there's am easy sample on the XNA homepage

You mean this one?
http://creators.xna.com/en-US/sample/winforms_series1

This topic is closed to new replies.

Advertisement