Click here to Skip to main content
15,909,193 members
Home / Discussions / WPF
   

WPF

 
QuestionOne Object Data Provider - Binding two datagrid Pin
Michael Sync20-Jul-08 7:31
Michael Sync20-Jul-08 7:31 
AnswerRe: One Object Data Provider - Binding two datagrid Pin
Jammer20-Jul-08 10:47
Jammer20-Jul-08 10:47 
GeneralRe: One Object Data Provider - Binding two datagrid Pin
Michael Sync20-Jul-08 21:36
Michael Sync20-Jul-08 21:36 
GeneralRe: One Object Data Provider - Binding two datagrid Pin
Jammer20-Jul-08 22:52
Jammer20-Jul-08 22:52 
QuestionDragSource Event ... has it been removed??? Pin
Jammer20-Jul-08 1:38
Jammer20-Jul-08 1:38 
AnswerRe: DragSource Event ... has it been removed??? Pin
Mark Salsbery20-Jul-08 8:46
Mark Salsbery20-Jul-08 8:46 
GeneralRe: DragSource Event ... has it been removed??? Pin
Jammer20-Jul-08 10:49
Jammer20-Jul-08 10:49 
QuestionWPF and Texture mapping.. need some help =( Pin
SilverD20-Jul-08 0:51
SilverD20-Jul-08 0:51 
Hello people!
I am a bit new to WPF (worked with WinForms till now). What am I trying to do is a sort of texture mapping.
When I was warking with WinForms I was using Directx SDK.
In my program I am getting a byte array that represents pixels in RGB format. for example byte[] arr = {r1,b1,g1,r2,b2,g2...rn,bn,gn};

So each 3 array cells represent one pixel. Then I was creating a MemoryStream. I had pre-written BMP file header, so I just write my header into the stream and then write my array there as well. So now I've got a Stream that represents a BMP image.
Now I've got my image in the stream. Then, in WinForms+ DirectX SDK I was creating a triangle primitive and was drawing my BMP image on this primitive ( texture mapping);



Now I want to do the same thing in WPF. I still have my byte[] arr ;
Here is the code of what I've done:

First of all this is my "Primitive class"

class PpiSegment : ModelVisual3D
{
MeshGeometry3D segmentMesh;
DiffuseMaterial segmentMaterial;

BitmapImage segmentTexture;
ImageSource segmentTextureSource;
ImageBrush segmentBrush;

// I get 3 points coordinates in the Constructor
public Segment(Point3D leftPoint, Point3D rightPoint, Point3D middlePoint)
{
segmentMesh = new MeshGeometry3D();
segmentMaterial = new DiffuseMaterial();

segmentTexture = new BitmapImage();
segmentBrush = new ImageBrush();

this.Content = new GeometryModel3D();
(this.Content as GeometryModel3D).Geometry = CreateTriangleCoords(leftPoint, rightPoint, middlePoint);



}






/* middle(center)
* /\
* / \
* / \
* / \
* left -------- right
*
*/
internal Geometry3D CreateTriangleCoords(Point3D leftPoint, Point3D rightPoint, Point3D middlePoint)
{

segmentMesh.Positions.Add(leftPoint);
segmentMesh.Normals.Add((Vector3D)leftPoint);
segmentMesh.TextureCoordinates.Add(new Point(1.0, 1.0));

segmentMesh.Positions.Add(rightPoint);
segmentMesh.Normals.Add((Vector3D)rightPoint);
segmentMesh.TextureCoordinates.Add(new Point(1.0, 1.0));

segmentMesh.Positions.Add(middlePoint);
segmentMesh.Normals.Add((Vector3D)middlePoint);
segmentMesh.TextureCoordinates.Add(new Point(0.0, 0.0));

segmentMesh.TriangleIndices.Add(2);
segmentMesh.TriangleIndices.Add(1);
segmentMesh.TriangleIndices.Add(0);


segmentMesh.Freeze();
return segmentMesh;
}
-----------------------------------------------------------------------------------------------------------
and now to the interresting part:
Here I am giving a BMP stream as an Image for the Brush.


//This Stream WAS INITIALIZED Before.
public Stream bitmapStream = new MemoryStream();


//On the first run of my class I call for this function to initialize the "StreamSource" parameter of
"segmentTexture"

public void SetTexture()
{


segmentTexture.BeginInit();
segmentTexture.StreamSource = bitmapStream;
segmentTexture.EndInit();


segmentTextureSource = segmentTexture;
segmentBrush.ImageSource = segmentTextureSource;
segmentMaterial.Brush = segmentBrush;

(this.Content as GeometryModel3D).Material = segmentMaterial;
this.Transform = new TranslateTransform3D(0.0, 0.0, 0.0);
}

Ok, I've got my image loaded. BUT! Now I need to change the image!
So I create somewhere a NEW stream and I amtrying to pass it like I did it before..

public void SetNewTexture(Stream newStream)
{

//I dont need Init/EndInit functions any more... (Don't I?)
segmentTexture.StreamSource = newStream;


segmentTextureSource = segmentTexture;
segmentBrush.ImageSource = segmentTextureSource;
segmentMaterial.Brush = segmentBrush;

(this.Content as GeometryModel3D).Material = segmentMaterial;
this.Transform = new TranslateTransform3D(0.0, 0.0, 0.0);
}

}

But! When I do that NOTHING happens... Image on my triangle primitive doesnt change...

-------------------------------------------------------------------------------------------------------------------------------

Here How I use my Segment class.. maybe its the problem....


class SegmentsBuilder
{
private ModelVisual3D _mv3D;
public PpiSegment[] segmentsArray;


//I am getting a "modelVisual3D" parameter from Window1.xaml
public SegmentsBuilder(ModelVisual3D modelVisual3D)
{
_mv3D = modelVisual3D;

segmentsArray = new PpiSegment[General.numberOfSegments];
}


//I am creating a circle from some number of triangles with textures on them
public void BuildSegments()
{
Point3D leftPoint, rightPoint, middlePoint;

double theta = MathHelper.DegToRad(360.0 / General.numberOfSegments);
double R = 0.95;
middlePoint = new Point3D(0.0, 0.0, General.ppiZCoordinate);

// create a list of triangles
for (int i = 0; i < General.numberOfBeems; i++)
{
//left
leftPoint = new Point3D();

leftPoint.X = R * Math.Cos((double)(i + 1) * theta);
leftPoint.Y = R * Math.Sin((double)(i + 1) * theta);
leftPoint.Z = General.ppiZCoordinate;

//right
rightPoint = new Point3D();

rightPoint.X = R * Math.Cos((double)(i) * theta);
rightPoint.Y = R * Math.Sin((double)(i) * theta);
rightPoint.Z = General.ppiZCoordinate;


segmentsArray[i] = new PpiSegment(rightPoint,leftPoint, middlePoint);
_mv3D.Children.Add(segmentsArray[i]);
}



}


public void UpdateTexture(int segment, Stream texture)
{

segmentsArray[segment].SetNewTexture(texture);


}

So here are my questions...
1)What do I do wrong? Why nothing happens over there?...
2)As I said before I am WPF noobie, so maybe there is another way of doing texture mapping, or doing my task (drawing a bitmap on the triangle)

Any help/ideas/opinions are really welcome... :]
AnswerRe: WPF and Texture mapping.. need some help =( Pin
Insincere Dave21-Jul-08 7:39
Insincere Dave21-Jul-08 7:39 
GeneralRe: WPF and Texture mapping.. need some help =( Pin
SilverD24-Jul-08 7:30
SilverD24-Jul-08 7:30 
QuestionRead XAML file Pin
Krishnraj18-Jul-08 21:56
Krishnraj18-Jul-08 21:56 
AnswerRe: Read XAML file Pin
yanairon19-Jul-08 21:18
yanairon19-Jul-08 21:18 
GeneralRe: Read XAML file Pin
Krishnraj20-Jul-08 19:06
Krishnraj20-Jul-08 19:06 
QuestionHow to set the startup object in WPF? Pin
Michael Sync17-Jul-08 0:46
Michael Sync17-Jul-08 0:46 
AnswerRe: How to set the startup object in WPF? Pin
Wes Aday17-Jul-08 9:15
professionalWes Aday17-Jul-08 9:15 
GeneralRe: How to set the startup object in WPF? Pin
Michael Sync17-Jul-08 16:32
Michael Sync17-Jul-08 16:32 
AnswerRe: How to set the startup object in WPF? Pin
John Ad18-Jul-08 4:02
John Ad18-Jul-08 4:02 
GeneralRe: How to set the startup object in WPF? Pin
Michael Sync18-Jul-08 4:16
Michael Sync18-Jul-08 4:16 
QuestionHow to find a particular entity in the listview and color it Pin
chandra vempati16-Jul-08 4:37
chandra vempati16-Jul-08 4:37 
AnswerRe: How to find a particular entity in the listview and color it Pin
MIHAI_MTZ16-Jul-08 21:38
MIHAI_MTZ16-Jul-08 21:38 
AnswerRe: How to find a particular entity in the listview and color it Pin
Yajnesh Narayan Behera20-Jul-08 23:27
Yajnesh Narayan Behera20-Jul-08 23:27 
QuestionWhen the control's content is displayed? :confused: Pin
Ryzhiy16-Jul-08 2:39
Ryzhiy16-Jul-08 2:39 
AnswerRe: When the control's content is displayed? :confused: Pin
Mark Salsbery16-Jul-08 7:27
Mark Salsbery16-Jul-08 7:27 
GeneralRe: When the control's content is displayed? :confused: Pin
Ryzhiy16-Jul-08 23:34
Ryzhiy16-Jul-08 23:34 
QuestionAdd Singleton UserControl in WPF Pin
ezazazel15-Jul-08 23:51
ezazazel15-Jul-08 23:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.