Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  AffineTransform to String to AffineTransform  (Read 1714 times)
0 Members and 1 Guest are viewing this topic.
Offline Shigsy

Junior Member




Im great, your not!


« Posted 2005-02-22 16:45:41 »

Well the title says it all really...
Ive converted an AffineTransoform to a String, and if i print that String it looks like this:

"AffineTransform[[1.0, 0.0, 25.0], [0.0, 1.0, 10.0]]"

So now i need to convert that String back into an AffineTransform. Can somebody please help me?
Thanks.

I can resist everything except temptation!
Offline Valodim

Junior Member




*sigh*


« Reply #1 - Posted 2005-02-22 17:41:01 »

wtf? why would anyone want to do that?? o_O

anyways, break up the string using indexof and then use stringtokenizer and integer.valueof to get the values back...
Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #2 - Posted 2005-02-23 04:54:51 »

I agree on both of Valodim's points

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Games published by our own members! Check 'em out!
Try the Free Demo of Titan Attacks
Offline Shigsy

Junior Member




Im great, your not!


« Reply #3 - Posted 2005-02-23 08:56:58 »

well im transfering an AffineTransform over a network (UDP) so it goes into a byte array before its sent. I need to convert it back from the byte array, into an AffineTransform at the other end.
Is there a better way to do this?

I can resist everything except temptation!
Offline Daniel_F

Junior Member


Projects: 2


Java games rock!


« Reply #4 - Posted 2005-02-23 09:05:52 »

Quote
well im transfering an AffineTransform over a network (UDP) so it goes into a byte array before its sent. I need to convert it back from the byte array, into an AffineTransform at the other end.
Is there a better way to do this?


Take a look at java.io.ObjectInputStream and java.io.ObjectOutputStream, with them you can write/read an object to/from a stream.
You may want to attach it to a ByteArrayOutputStream to write it to a byte array. (and read with ByteArrayInputStream)
Offline Shigsy

Junior Member




Im great, your not!


« Reply #5 - Posted 2005-02-23 09:52:48 »

The problem is i have 6 different values to send. They are all primative data type accept the 2 AffineTransforms so thought it would be quicker to send them in a String, then send an object.
Ill try send the values that the AffineTransforms are made up of, and construct them from the values at the other end.
If anyone gets a better idea, let me know. Thanks.

I can resist everything except temptation!
Offline Daniel_F

Junior Member


Projects: 2


Java games rock!


« Reply #6 - Posted 2005-02-23 10:22:50 »

Quote
The problem is i have 6 different values to send. They are all primative data type accept the 2 AffineTransforms so thought it would be quicker to send them in a String, then send an object.
Ill try send the values that the AffineTransforms are made up of, and construct them from the values at the other end.
If anyone gets a better idea, let me know. Thanks.


Fortunately the ObjectOutputStream can write primitive data types too. (with writeByte,writeFloat etc...)

Example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
//Writing
ByteArrayOutputStream baos=new ByteArrayOutputStream();
ObjectOutputStream oos=new ObjectOutputStream(baos);
oos.writeFloat(0.4f);
oos.writeObject("Hello");
byte[] b=baos.toByteArray(); // Here you have the byte array with the data, send it anywhere

//...

//Reading from a byte array "b"
ObjectInputStream ois=new ObjectInputStream(new ByteArrayInputStream(b));
float f=ois.readFloat();
String s=(String)ois.readObject();


Although if somebody has a better solution, I would like to see.
Offline Valodim

Junior Member




*sigh*


« Reply #7 - Posted 2005-02-23 18:48:31 »

Quote
public class AffineTransform
extends Object
implements Cloneable, Serializable


how about serializing and sending the affinetransform object, then sending the other primitive types? Roll Eyes
Offline Shigsy

Junior Member




Im great, your not!


« Reply #8 - Posted 2005-02-26 08:30:13 »

thanks for all your suggestions btw. Ive sent all the data over like u seggested Daniel_F. I have a question though.
If i do soemthing like this...

writeObject()
writeObject()
writeInt()
writeInt()

then at the other end i do this...

readObject()
readObject()
readInt()
readInt()

will it keep them in order? I mean, will the 1st readObject() read in what was written using the first writeObject()..etc?

I can resist everything except temptation!
Offline Daniel_F

Junior Member


Projects: 2


Java games rock!


« Reply #9 - Posted 2005-02-26 08:54:37 »

Quote

...
will it keep them in order? I mean, will the 1st readObject() read in what was written using the first writeObject()..etc?


I think yes, otherwise it would be pretty useless.  Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Valodim

Junior Member




*sigh*


« Reply #10 - Posted 2005-02-28 20:10:30 »

most probable, but not 100% guaranteed with udp Smiley
Offline tom
« Reply #11 - Posted 2005-02-28 20:58:02 »

Quote
most probable, but not 100% guaranteed with udp Smiley

?

Udp don't have guaranteed delivery but the content sent is guaranteed to be the same as recieved.

Offline Valodim

Junior Member




*sigh*


« Reply #12 - Posted 2005-02-28 21:02:40 »

Quote
Udp don't have guaranteed delivery but the content sent is guaranteed to be the same as recieved.


umm... how can the content sent be guaranteed to be the same as received if some packages may just get lost on the way?? o_O
Offline Abuse

JGO Coder


Medals: 2


falling into the abyss of reality


« Reply #13 - Posted 2005-02-28 22:31:04 »

Quote


umm... how can the content sent be guaranteed to be the same as received if some packages may just get lost on the way?? o_O


If a datagram/packet is recieved, then you can be *almost* assured that it will be identical to what was sent.

Its upto you to determine if there are any missing packets.

How did this get onto the ins and outs UDP?
The question was about transfering Objects across a network - for which you would almost certainly want to use TCP anyway =/

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
Offline Valodim

Junior Member




*sigh*


« Reply #14 - Posted 2005-03-01 13:59:46 »

that's what I was trying to point out - use tcp for this kind of transfer Tongue
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (115 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.144 seconds with 20 queries.