Archived

This topic is now archived and is closed to further replies.

IStrikerI

stupid c# d3d9

Recommended Posts

IStrikerI    122
what type of variable is this Device.Transform.View ? for example this doesnt work: dev.Transform.View.M11 = 1; // not a variable ? what else ? this doesnt work: dev.Transform.View = new Matrix(); dev.Transform.View.M11 = 1; and what the hell does this function Matrix.PerspectiveFovLH()? does it return a new instance ? this cannot be, i already did it and it doesnt work. it also isnt a fu***** static variable. sorry, but im very angry about the fact that the prog-languages get slower and more complicated than c++

Share this post


Link to post
Share on other sites
danrok    122
PerspectiveFovLH builds a left-handed perspective projection matrix based on a field of view and expects 5 parameters. Maybe thats why it doesn''t work?

Matrix.PerspectiveFovLH()...

Share this post


Link to post
Share on other sites
Hawkeye3    122
PerspectiveFovLH Method
C#

public static Matrix PerspectiveFovLH(
float fieldOfViewY,
float aspectRatio,
float znearPlane,
float zfarPlane
);

Return Value

Microsoft.DirectX.Matrix

Share this post


Link to post
Share on other sites
IStrikerI    122
i know what mathematical stuff the function does, but i dont know how the function returns the matrix and what type of variable Device.Transform.View is.

this works, but how ?
Device.Transform.View = PerspectiveFovLH(0, 0, 0, 0);


is Device.Transform.View already referencing to an instance or not or is it static ?

Share this post


Link to post
Share on other sites
budipro    122
If I''m not mistaken, Device.Transform.View is a read-only property, so you can''t alter it, but you can get the value. Its type is Matrix.

Bear in mind that C# has "properties", which C++ doesn''t have.

Share this post


Link to post
Share on other sites
IStrikerI    122
Device.Transform.View cannot be readonly because this works:
Device.Transform.View = PerspectiveFovLH(0, 0, 0, 0);
this is also an example from msdn

okok Device.Transform.Projection = PerspectiveFovLH(0, 0, 0, 0);
would be better ;-)

[edited by - IStrikerI on September 3, 2003 10:39:32 AM]

Share this post


Link to post
Share on other sites
nerdboy80    128
In C# something is either a value-type (basically a struct from C/C++) or a reference type (a pointer to an instance of a class).

Matrix is a value type (it inherits from System.ValueType). Because you don''t get references to value types, a property that returns a value type will return a copy of it, not the value type itself.

So, Device.Transform.View returns a COPY of the View matrix. If Matrix was a reference type, the Device.Transform.View would return the actual view matrix (well, the reference to the actual view matrix).

So, if you want to muck with the view matrix (or some other matrix), you ususally need to do something like:

Matrix m = Device.Transform.View;
m.M11 = 1.0f;
Device.Transform.View = m; // (or Device.SetTransform(TransformType.View, m)

I had the same problem with the Viewport until I realized my error.

Cheers,
nerdboy80

Share this post


Link to post
Share on other sites
Nypyren    12074
Uhm, how about:


device.Transform.View = Matrix.PerspectiveFovLH(90, 4f/3f, 1, 1000);


Matrix.PerspectiveFovLH is a static member function. That means that you don't call it from a Matrix object, you just call it like so. It creates and returns a Matrix object that you can use for whatever you want.

How does it work?


public class Matrix
{
public static Matrix PerspectiveFovLH(...)
{
Matrix m = new Matrix();
// fills the matrix
return m;
}
}


Device.TransForm.View is of type Matrix, and has both getter and setter.

And yes, properties that are of a value-type cannot be modified without using a temporary (value-types returned by a getter are treated as temporary constants by the compiler)



You don't need C# for DX9. DX9 provides both COM+ and .NET interfaces, so you can use it in C++, Managed C++, C#, VB.Net and any other languages that support either COM or .NET interop.

[edited by - Nypyren on September 3, 2003 8:39:41 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Anonymous Poster
Does any one know if you need C# for DX 9?


You can use DX 9 with a variety of languages. C/C++, C#, VB to name a few, and there are probably a few others.

Share this post


Link to post
Share on other sites
IStrikerI    122
so if i want to set the viewmatrix by myself (not using an existing function from d3d9) i just do this:

Matrix m = new Matrix();
// fill matrix with my own values

Device.Transform.View = m;

but you say Matrix is value-type. why do i need to instantiate it with new?

(sorry i cant test it in the moment im not at home)

@anonymous poster
im not planning to use c# for d3d9. i play around with it just for fun.

Share this post


Link to post
Share on other sites
wingcom    122
value type is either an enum or a struct, so it can be either created in the stack or heap. By using the keyword new, you are creating the object in the heap.

hope this helps

Share this post


Link to post
Share on other sites