Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (521)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
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 2127 times)
0 Members and 1 Guest are viewing this topic.
Offline Shigsy

Junior Devvie




Im great, your not!


« Posted 2005-02-22 15: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 Devvie




*sigh*


« Reply #1 - Posted 2005-02-22 16: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 Devvie




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


« Reply #2 - Posted 2005-02-23 03: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!
Legends of Yore - The Casual Retro Roguelike
Offline Shigsy

Junior Devvie




Im great, your not!


« Reply #3 - Posted 2005-02-23 07: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 Devvie


Projects: 2


Java games rock!


« Reply #4 - Posted 2005-02-23 08: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 Devvie




Im great, your not!


« Reply #5 - Posted 2005-02-23 08: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 Devvie


Projects: 2


Java games rock!


« Reply #6 - Posted 2005-02-23 09: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 Devvie




*sigh*


« Reply #7 - Posted 2005-02-23 17: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 Devvie




Im great, your not!


« Reply #8 - Posted 2005-02-26 07: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 Devvie


Projects: 2


Java games rock!


« Reply #9 - Posted 2005-02-26 07: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 Devvie




*sigh*


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

most probable, but not 100% guaranteed with udp Smiley
Offline tom
« Reply #11 - Posted 2005-02-28 19: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 Devvie




*sigh*


« Reply #12 - Posted 2005-02-28 20: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 Knight


Medals: 14


falling into the abyss of reality


« Reply #13 - Posted 2005-02-28 21: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! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Valodim

Junior Devvie




*sigh*


« Reply #14 - Posted 2005-03-01 12: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.

 

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

The first screenshot will be displayed as a thumbnail.

xFryIx (52 views)
2014-11-13 03:34:49

digdugdiggy (34 views)
2014-11-12 12:11:50

digdugdiggy (29 views)
2014-11-12 12:10:15

digdugdiggy (23 views)
2014-11-12 12:09:33

kovacsa (46 views)
2014-11-07 10:57:14

TehJavaDev (50 views)
2014-11-03 13:04:50

BurntPizza (49 views)
2014-11-03 09:54:52

moogie (65 views)
2014-11-02 21:22:04

CopyableCougar4 (63 views)
2014-11-01 14:36:41

DarkCart (148 views)
2014-11-01 05:51:03
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 13:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 13:36:02

List of Learning Resources
by Longor1996
2014-08-16 01:40:00

List of Learning Resources
by SilverTiger
2014-08-05 10:33:27

Resources for WIP games
by CogWheelz
2014-08-01 07:20:17

Resources for WIP games
by CogWheelz
2014-08-01 07:19:50

List of Learning Resources
by SilverTiger
2014-07-31 07:29:50

List of Learning Resources
by SilverTiger
2014-07-31 07:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!