public void Draw(Sprite d3dSprite) {
if (isVisible) {
d3dSprite.Draw(this.Texture, // Source Texure
new Rectangle(0,0,width,height),// Source Rectangle
new Vector2(scale,scale), // Scaling
new Vector2(width/2f,height/2f),// Rotation Center
visualAngle, // Rotation
position, // Translation
Color.White.ToArgb()); // Alpha (?) Color
}
}
[.net] Sprite Scale in vers: 1.0.2902.0
Greetings Everyone,
This is my first post to the community and don’t believe it to be my last...
I am a beginning game developer and have gained a real respect for game programmers over the last few months... (this is tough stuff). Wished I'd have paid more attention in math class.
In any event, I've run into a problem that has beaten me up pretty good. I have looked everywhere for some kind of hint and found none... so here I am… posting to the forum.
Before I whacked my box I was running Direct3D version: 1.0.900.0
I am now running VS 2003, framework 1.1.4322, and DirectX: 1.0.2902.0
I am working with the Sprite object in Direct3D (all in Managed C#).
Now, before I whacked my box and installed the latest (and greatest?) versions, I was making a call to the Draw function like this:
But, in this newest version (1.0.2902.0), they've changed it. "Scaling" is now "Destination Rectangle". There is a huge difference between these two methods for scaling the Sprite. The 'old' method of Scaling actually drew the Sprite X many pixels larger (or smaller). But this new method "destRect" seems to be making the pixels larger. (thus keeping the same size in pixels)
I wish that I could explain what I am experiencing better. It seems that the 'old' Scaling scaled the sprite in screen coordinates while the new destRect is scaling it in some other way (maybe object coordinates?)
I want to scale the sprites in the 'old' manner. Meaning: when I tell a 100 pixel sprite (in actual screen pixels) to be 2x as large, I want the sprite to render at 200 pixels (actual screen pixels). Not 100 pixels that are twice as large. Lol does this make sense?
I hope someone can help, this one problem has held me up for 4 long days.
Ok, cool, I'm excited to be apart of this community and am eager to learn anything you wish to share.
[Edited by - ElectricBliss on October 9, 2004 11:11:47 PM]
I thought I’d post my current solution. I skipped trying to use the Sprite’s transforms and just used a matrix instead. Please let me know if there is a more elegant solution.
[Edited by - ElectricBliss on October 10, 2004 11:43:56 PM]
public void Draw(Sprite d3dSprite) { if (isVisible) { Matrix m = new Matrix(); m.Transform(new Vector3(0f,0f,0f),//scale Center new Quaternion(0f,0f,0f,0f), //scaling rotation new Vector3(ScaleX,ScaleY,0f), //scaling factor new Vector3(0f,0f,0f), //rotation center new Quaternion(0f,0f,0f,0f), //rotation new Vector3(X,Y,0f)); //translation d3dSprite.Transform = m; d3dSprite.Draw(this.Texture, //texture new Rectangle(0,0,width,height), //source rectangle new Vector3(0f,0f,0f), //center new Vector3(0f,0f,0f), //position Color.White); //alpha color }}
[Edited by - ElectricBliss on October 10, 2004 11:43:56 PM]
Quote:Original post by ElectricBliss
...Wished I'd have paid more attention in math class...
Sorry that I can't comment on the Sprite.
If you are trying to get started, a good book helps a great amount. My book had an introduction to matrices, vectors and quaternions. It was with DX 8 so you probably don't want the name.
(I am good at maths in the additional set in my school where we learn some A level maths as well as GCSE, but we only used vectors and matrices for simple translation (no dot/cross products or anything!) and we have certainly not done quaternions :~})
Greetings all,
Just thought I'd update ya on the scaling with Matrices. Just use the Transform2D function to KISS:
Just thought I'd update ya on the scaling with Matrices. Just use the Transform2D function to KISS:
Matrix m = new Matrix();m = Matrix.Transformation2D( new Vector2(0f,0f), //scaleCenter 0f, new Vector2(ScaleX, ScaleY),//scaling rotation, scaling new Vector2(0f,0f), //rotation center this.rotation, //rotation new Vector2(X,Y)); //translationd3dSprite.Transform = m;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement