Tampilkan postingan dengan label C#. Tampilkan semua postingan
Tampilkan postingan dengan label C#. Tampilkan semua postingan

Kamis, 02 September 2010

Augmented Reality : C# + ARToolkits

Setelah mencoba mencari2 tutorial AR yang berbasis C# akhirnya nemu juga..
contohnya bisa di download disini




sequence diagram dari tahapan AR menggunakan WPF dan ARToolkits

sequend diagram diatas menggambarkan secara umum bagaimana AR bekerja untuk lebih lanjut bisa di pelajari dari link2 terkait buat belajar Augmented Reality :

http://sites.google.com/site/augmentedrealitytestingsite/

http://www.mperfect.net/wpfAugReal/

buat yang blom bisa programming, bisa pake software buatan hitlabnz.org linknya disini

Contoh video :


Animasi Pesawatnya minta dibuatin ke Temen yang jago 3D :D ...
Lumayan juga..
READ MORE - Augmented Reality : C# + ARToolkits

Game Programming pake XNA 2.0



XNA 2.0 Game Programming Recipes

Riemer Grootjans







On this page, you can download the accompanying code for the book “XNA 2.0 Game Programming Recipes”.

This section also contains a description of the Table of Contents of the book. At the bottom of this page, you can find a short summary on all chapters. Click on the chapter to go a page with more details on the chapter.

Code Download

Click on the links below to download the code for each chapter:

Download code for Chapter 1
Download code for Chapter 2
Download code for Chapter 3
Download code for Chapter 4
Download code for Chapter 5
Download code for Chapter 6
Download code for Chapter 7
Download code for Chapter 8


READ MORE - Game Programming pake XNA 2.0

Use NetworkStream to read and write to a server

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

class MainClass
{
public static void Main()
{
IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);

Socket server = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);

try
{
server.Connect(ip);
} catch (SocketException e){
Console.WriteLine(e.ToString());
return;
}

NetworkStream ns = new NetworkStream(server);

while(true)
{
byte[] data = new byte[1024];
string input = Console.ReadLine();
if (ns.CanWrite){
ns.Write(Encoding.ASCII.GetBytes(input), 0, input.Length);
ns.Flush();
}

int receivedDataLength = ns.Read(data, 0, data.Length);
string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
Console.WriteLine(stringData);
}

ns.Close();
server.Shutdown(SocketShutdown.Both);
server.Close();
}
}
READ MORE - Use NetworkStream to read and write to a server

Handle network exceptions

using System;
using System.Net;
using System.IO;

class MainClass {
public static void Main() {
int ch;

try {

HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://www.buthlan.name");

HttpWebResponse resp = (HttpWebResponse) req.GetResponse();

Stream istrm = resp.GetResponseStream();

for(int i=1; ; i++) {
ch = istrm.ReadByte();
if(ch == -1)
break;
Console.Write((char) ch);
}

resp.Close();

} catch(WebException exc) {
Console.WriteLine("Network Error: " + exc.Message +
"\nStatus code: " + exc.Status);
} catch(ProtocolViolationException exc) {
Console.WriteLine("Protocol Error: " + exc.Message);
} catch(UriFormatException exc) {
Console.WriteLine("URI Format Error: " + exc.Message);
} catch(NotSupportedException exc) {
Console.WriteLine("Unknown Protocol: " + exc.Message);
} catch(IOException exc) {
Console.WriteLine("I/O Error: " + exc.Message);
} catch(System.Security.SecurityException exc) {
Console.WriteLine("Security Exception: " + exc.Message);
} catch(InvalidOperationException exc) {
Console.WriteLine("Invalid Operation: " + exc.Message);
}
}
}
READ MORE - Handle network exceptions

Catch Socket exception

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

class MainClass
{
public static void Main()
{
IPAddress host = IPAddress.Parse("192.168.1.1");
IPEndPoint hostep = new IPEndPoint(host, 8000);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

try
{
sock.Connect(hostep);
} catch (SocketException e) {
Console.WriteLine("Problem connecting to host");
Console.WriteLine(e.ToString());
sock.Close();
return;
}

sock.Close();
}
READ MORE - Catch Socket exception

NetworkStream from a Socket

using System;
using System.IO;
using System.Net.Sockets ;

class MainClass
{
public static void Main()
{
TcpListener tcpl = new TcpListener(9999);
tcpl.Start();

for (;;)
{
Socket newSocket = tcpl.AcceptSocket();
if (newSocket.Connected)
{
NetworkStream ns = new NetworkStream(newSocket);

byte[] buf = {1,2,3,4,5,6,7,8,9};
ns.Write(buf, 0, 9);

ns.Flush();
ns.Close();

}
newSocket.Close();
break;

}
}

}
READ MORE - NetworkStream from a Socket

Contoh-Contoh Query LINQ

Contoh 1

public void SimpleQuery()

{

DataClasses1DataContext dc = new DataClasses1DataContext();

var q =

from a in dc.GetTable<Order>()

select a;

dataGridView1.DataSource = q;

}




Contoh 2

public void SimpleQuery2()
{
DataClasses1DataContext dc = new DataClasses1DataContext();
dataGridView1.DataSource = dc.GetTable<Order>();
}



Contoh 3

public void SimpleQuery3()

{

DataClasses1DataContext dc = new DataClasses1DataContext();

var q =

from a in dc.GetTable<Order>()

where a.CustomerID.StartsWith("A")

select a;

dataGridView1.DataSource = q;

}



Contoh 4

public void GetCustomerOrder()

{

DataClasses1DataContext dc = new DataClasses1DataContext();

var q= (from orders in dc.GetTable<Order>()

from orderDetails in dc.GetTable<Order_Detail>()

from prods in dc.GetTable<Product>()

where ((orderDetails.OrderID == orders.OrderID) &&

(prods.ProductID == orderDetails.ProductID) &&

(orders.EmployeeID == 1))

orderby orders.ShipCountry

select new CustomerOrderResult

{

CustomerID = orders.CustomerID,

CustomerContactName = orders.Customer.ContactName,

CustomerCountry = orders.Customer.Country,

OrderDate = orders.OrderDate,

EmployeeID = orders.Employee.EmployeeID,

EmployeeFirstName = orders.Employee.FirstName,

EmployeeLastName = orders.Employee.LastName,

ProductName = prods.ProductName

}).ToList<CustomerOrderResult>();

dataGridView1.DataSource = q;

}




sumber : http://www.c-sharpcorner.com/
READ MORE - Contoh-Contoh Query LINQ

Contoh LINQ : Join Query

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Customer
{
public string ID { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string Region { get; set; }
public decimal Sales { get; set; }
}
class Order
{
public string ID { get; set; }
public decimal Amount { get; set; }
}
class Program
{
static void Main(string[] args)
{
List orders = new List {
new Order { ID="X", Amount=900 },
new Order { ID="Y", Amount=1000 },
new Order { ID="Z", Amount=1100 }
};
List customers = new List {
new Customer { ID="X", City="Beijing", Country="China", Region="Asia", Sales=9000 },
new Customer { ID="Y", City="Bogotá", Country="Colombia", Region="South America", Sales=1001 },
new Customer { ID="Z", City="Lima", Country="Peru", Region="South America", Sales=2002 }
};

var queryResults =
from c in customers
join o in orders on c.ID equals o.ID
select new { c.ID, c.City, SalesBefore = c.Sales, NewOrder = o.Amount, SalesAfter = c.Sales+o.Amount };

foreach (var item in queryResults)
{
Console.WriteLine(item);
}
}
}
READ MORE - Contoh LINQ : Join Query

Thread Sederhana dengan ThreadStart

using System;
using System.Threading;

class MainClass
{
public static void DoCount()
{
for ( int i = 0; i < 10; i++ )
{
System.Console.WriteLine( "Reached {0}", i );
}
}

[STAThread]
static void Main(string[] args)
{
Thread t = new Thread( new ThreadStart( DoCount ) );
t.Start();
}
}
READ MORE - Thread Sederhana dengan ThreadStart

Encrypt Menggunakan RSACryptoServiceProvider

using System;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Text;

class Program
{
static void Main(string[] args)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
StreamReader sr = File.OpenText("myKey.xml");
string rsaXml = sr.ReadToEnd();
sr.Close();
rsa.FromXmlString(rsaXml);

string messageToJane = "this is a test";

byte[] encrypted = rsa.Encrypt(System.Text.ASCIIEncoding.ASCII.GetBytes(messageToJane), false);

FileStream fs = new FileStream("Message.dat", FileMode.Create);
fs.Write(encrypted, 0, encrypted.Length);
fs.Close();
}
}
READ MORE - Encrypt Menggunakan RSACryptoServiceProvider

Simple WebService

<%@ WebService Language="c#" Class="MathService"%>

using System;
using System.Web.Services;

[WebService(Namespace="http://localhost/test")]
public class MathService : WebService
{
[WebMethod]
public int Add(int a, int b)
{
return a + b;
}

[WebMethod]
public int Subtract(int a, int b)
{
return a - b;
}

[WebMethod]
public int Multiply(int a, int b)
{
return a * b;
}

[WebMethod]
public int Divide(int a, int b)
{
int answer;
if (b != 0)
{
answer = a / b;
return answer;
} else
return 0;
}
}

///////////////

using System;

class ServiceTest
{
public static void Main(string[] argv)
{
MathService ms = new MathService();

int x = Convert.ToInt16(argv[0]);
int y = Convert.ToInt16(argv[1]);

int sum = ms.Add(x, y);
int sub = ms.Subtract(x, y);
int mult = ms.Multiply(x, y);
int div = ms.Divide(x, y);
Console.WriteLine("The answers are:");
Console.WriteLine(" {0} + {1} = {2}", x, y, sum);
Console.WriteLine(" {0} - {1} = {2}", x, y, sub);
Console.WriteLine(" {0} * {1} = {2}", x, y, mult);
Console.WriteLine(" {0} / {1} = {2}", x, y, div);
}
}

READ MORE - Simple WebService